about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CMake/Googletest/CMakeLists.txt.in33
-rw-r--r--CMake/Googletest/DownloadGTest.cmake15
-rw-r--r--CMakeLists.txt10
-rw-r--r--LTS.md1
-rw-r--r--absl/strings/cord.cc2
-rw-r--r--absl/strings/internal/cord_internal.h3
-rw-r--r--absl/strings/internal/str_split_internal.h4
-rw-r--r--absl/strings/string_view.h11
-rw-r--r--absl/strings/string_view_test.cc8
-rw-r--r--absl/types/span.h2
-rw-r--r--absl/types/span_test.cc5
11 files changed, 62 insertions, 32 deletions
diff --git a/CMake/Googletest/CMakeLists.txt.in b/CMake/Googletest/CMakeLists.txt.in
index d60a33e9ac6a..994dac0bf70b 100644
--- a/CMake/Googletest/CMakeLists.txt.in
+++ b/CMake/Googletest/CMakeLists.txt.in
@@ -1,15 +1,26 @@
 cmake_minimum_required(VERSION 2.8.2)
 
-project(googletest-download NONE)
+project(googletest-external NONE)
 
 include(ExternalProject)
-ExternalProject_Add(googletest
-  GIT_REPOSITORY    https://github.com/google/googletest.git
-  GIT_TAG           master
-  SOURCE_DIR        "${CMAKE_BINARY_DIR}/googletest-src"
-  BINARY_DIR        "${CMAKE_BINARY_DIR}/googletest-build"
-  CONFIGURE_COMMAND ""
-  BUILD_COMMAND     ""
-  INSTALL_COMMAND   ""
-  TEST_COMMAND      ""
-)
\ No newline at end of file
+if(${ABSL_USE_GOOGLETEST_HEAD})
+  ExternalProject_Add(googletest
+    GIT_REPOSITORY    https://github.com/google/googletest.git
+    GIT_TAG           master
+    SOURCE_DIR        "${absl_gtest_src_dir}"
+    BINARY_DIR        "${absl_gtest_build_dir}"
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND     ""
+    INSTALL_COMMAND   ""
+    TEST_COMMAND      ""
+  )
+else()
+  ExternalProject_Add(googletest
+    SOURCE_DIR        "${absl_gtest_src_dir}"
+    BINARY_DIR        "${absl_gtest_build_dir}"
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND     ""
+    INSTALL_COMMAND   ""
+    TEST_COMMAND      ""
+  )
+endif()
\ No newline at end of file
diff --git a/CMake/Googletest/DownloadGTest.cmake b/CMake/Googletest/DownloadGTest.cmake
index 8a00b4550c7e..6552e1da1dc4 100644
--- a/CMake/Googletest/DownloadGTest.cmake
+++ b/CMake/Googletest/DownloadGTest.cmake
@@ -1,10 +1,11 @@
-# Downloads and unpacks googletest at configure time.  Based on the instructions
-# at https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
+# Integrates googletest at configure time.  Based on the instructions at
+# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
 
-# Download the latest googletest from Github master
+# Set up the external googletest project, downloading the latest from Github
+# master if requested.
 configure_file(
   ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in
-  ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
+  ${CMAKE_BINARY_DIR}/googletest-external/CMakeLists.txt
 )
 
 set(ABSL_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
@@ -14,17 +15,17 @@ if (BUILD_SHARED_LIBS)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1")
 endif()
 
-# Configure and build the downloaded googletest source
+# Configure and build the googletest source.
 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
   RESULT_VARIABLE result
-  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external )
 if(result)
   message(FATAL_ERROR "CMake step for googletest failed: ${result}")
 endif()
 
 execute_process(COMMAND ${CMAKE_COMMAND} --build .
   RESULT_VARIABLE result
-  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external)
 if(result)
   message(FATAL_ERROR "Build step for googletest failed: ${result}")
 endif()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdfb2cfa864f..74b5cd9ddca4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,6 +84,10 @@ find_package(Threads REQUIRED)
 option(ABSL_USE_GOOGLETEST_HEAD
   "If ON, abseil will download HEAD from googletest at config time." OFF)
 
+set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH
+  "If ABSL_USE_GOOGLETEST_HEAD is OFF, specifies the directory of a local googletest checkout."
+  )
+
 option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
 
 if(${ABSL_RUN_TESTS})
@@ -96,11 +100,13 @@ endif()
 ## check targets
 if(BUILD_TESTING)
 
+  set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
   if(${ABSL_USE_GOOGLETEST_HEAD})
-    include(CMake/Googletest/DownloadGTest.cmake)
     set(absl_gtest_src_dir ${CMAKE_BINARY_DIR}/googletest-src)
-    set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
+  else()
+    set(absl_gtest_src_dir ${ABSL_LOCAL_GOOGLETEST_DIR})
   endif()
+  include(CMake/Googletest/DownloadGTest.cmake)
 
   check_target(gtest)
   check_target(gtest_main)
diff --git a/LTS.md b/LTS.md
index 94363b6a36f1..ade8b17c7367 100644
--- a/LTS.md
+++ b/LTS.md
@@ -13,3 +13,4 @@ The following lists LTS branches and the dates on which they have been released:
 * [LTS Branch December 18, 2018](https://github.com/abseil/abseil-cpp/tree/lts_2018_12_18/)
 * [LTS Branch June 20, 2018](https://github.com/abseil/abseil-cpp/tree/lts_2018_06_20/)
 * [LTS Branch August 8, 2019](https://github.com/abseil/abseil-cpp/tree/lts_2019_08_08/)
+* [LTS Branch February 25, 2020](https://github.com/abseil/abseil-cpp/tree/lts_2020_02_25/)
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc
index d9503ae332d7..5cc68539941d 100644
--- a/absl/strings/cord.cc
+++ b/absl/strings/cord.cc
@@ -136,8 +136,6 @@ inline const CordRepExternal* CordRep::external() const {
 
 static const size_t kFlatOverhead = offsetof(CordRep, data);
 
-static_assert(kFlatOverhead == 13, "Unittests assume kFlatOverhead == 13");
-
 // Largest and smallest flat node lengths we are willing to allocate
 // Flat allocation size is stored in tag, which currently can encode sizes up
 // to 4K, encoded as multiple of either 8 or 32 bytes.
diff --git a/absl/strings/internal/cord_internal.h b/absl/strings/internal/cord_internal.h
index 5b5d10830891..830ceaf473bd 100644
--- a/absl/strings/internal/cord_internal.h
+++ b/absl/strings/internal/cord_internal.h
@@ -86,8 +86,7 @@ struct CordRepExternal;
 struct CordRep {
   // The following three fields have to be less than 32 bytes since
   // that is the smallest supported flat node size.
-  // We use uint64_t for the length even in 32-bit binaries.
-  uint64_t length;
+  size_t length;
   Refcount refcount;
   // If tag < FLAT, it represents CordRepKind and indicates the type of node.
   // Otherwise, the node type is CordRepFlat and the tag is the encoded size.
diff --git a/absl/strings/internal/str_split_internal.h b/absl/strings/internal/str_split_internal.h
index b54f6ebe09e0..6f5bc095fbbe 100644
--- a/absl/strings/internal/str_split_internal.h
+++ b/absl/strings/internal/str_split_internal.h
@@ -65,8 +65,8 @@ class ConvertibleToStringView {
       : value_(s) {}
 
   // Matches rvalue strings and moves their data to a member.
-ConvertibleToStringView(std::string&& s)  // NOLINT(runtime/explicit)
-    : copy_(std::move(s)), value_(copy_) {}
+  ConvertibleToStringView(std::string&& s)  // NOLINT(runtime/explicit)
+      : copy_(std::move(s)), value_(copy_) {}
 
   ConvertibleToStringView(const ConvertibleToStringView& other)
       : copy_(other.copy_),
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h
index 1861ea62a9ea..55e80d62ae80 100644
--- a/absl/strings/string_view.h
+++ b/absl/strings/string_view.h
@@ -382,11 +382,12 @@ class string_view {
   // Returns a "substring" of the `string_view` (at offset `pos` and length
   // `n`) as another string_view. This function throws `std::out_of_bounds` if
   // `pos > size`.
-  string_view substr(size_type pos, size_type n = npos) const {
-    if (ABSL_PREDICT_FALSE(pos > length_))
-      base_internal::ThrowStdOutOfRange("absl::string_view::substr");
-    n = (std::min)(n, length_ - pos);
-    return string_view(ptr_ + pos, n);
+  constexpr string_view substr(size_type pos, size_type n = npos) const {
+    return ABSL_PREDICT_FALSE(pos > length_)
+               ? (base_internal::ThrowStdOutOfRange(
+                      "absl::string_view::substr"),
+                  string_view())
+               : string_view(ptr_ + pos, Min(n, length_ - pos));
   }
 
   // string_view::compare()
diff --git a/absl/strings/string_view_test.cc b/absl/strings/string_view_test.cc
index 7b1d56fac762..cb6a758fea6f 100644
--- a/absl/strings/string_view_test.cc
+++ b/absl/strings/string_view_test.cc
@@ -1086,6 +1086,14 @@ TEST(StringViewTest, ConstexprCompiles) {
   EXPECT_EQ(sp_npos, -1);
 }
 
+TEST(StringViewTest, ConstexprSubstr) {
+  constexpr absl::string_view foobar("foobar", 6);
+  constexpr absl::string_view foo = foobar.substr(0, 3);
+  constexpr absl::string_view bar = foobar.substr(3);
+  EXPECT_EQ(foo, "foo");
+  EXPECT_EQ(bar, "bar");
+}
+
 TEST(StringViewTest, Noexcept) {
   EXPECT_TRUE((std::is_nothrow_constructible<absl::string_view,
                                              const std::string&>::value));
diff --git a/absl/types/span.h b/absl/types/span.h
index 3283145a56b4..25347c63fe8c 100644
--- a/absl/types/span.h
+++ b/absl/types/span.h
@@ -276,7 +276,7 @@ class Span {
   // Returns a reference to the i'th element of this span.
   constexpr reference operator[](size_type i) const noexcept {
     // MSVC 2015 accepts this as constexpr, but not ptr_[i]
-    return *(data() + i);
+    return ABSL_ASSERT(i < size()), *(data() + i);
   }
 
   // Span::at()
diff --git a/absl/types/span_test.cc b/absl/types/span_test.cc
index 22467a0a767e..6ac234d365ad 100644
--- a/absl/types/span_test.cc
+++ b/absl/types/span_test.cc
@@ -232,6 +232,11 @@ TEST(IntSpan, ElementAccess) {
 
   EXPECT_EQ(s.front(), s[0]);
   EXPECT_EQ(s.back(), s[9]);
+
+#ifndef NDEBUG
+  EXPECT_DEATH_IF_SUPPORTED(s[-1], "");
+  EXPECT_DEATH_IF_SUPPORTED(s[10], "");
+#endif
 }
 
 TEST(IntSpan, AtThrows) {