diff options
-rw-r--r-- | CMake/AbseilHelpers.cmake | 12 | ||||
-rw-r--r-- | absl/base/BUILD.bazel | 2 | ||||
-rw-r--r-- | absl/base/CMakeLists.txt | 2 | ||||
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 12 | ||||
-rw-r--r-- | absl/strings/numbers_test.cc | 4 | ||||
-rw-r--r-- | absl/synchronization/BUILD.bazel | 2 | ||||
-rw-r--r-- | absl/types/optional.h | 9 | ||||
-rw-r--r-- | absl/types/optional_test.cc | 53 |
8 files changed, 64 insertions, 32 deletions
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake index 7c81beaf9e8c..8fdd510ff24b 100644 --- a/CMake/AbseilHelpers.cmake +++ b/CMake/AbseilHelpers.cmake @@ -35,13 +35,13 @@ set(ABSL_IDE_FOLDER Abseil) # COPTS: List of private compile options # DEFINES: List of public defines # LINKOPTS: List of link options -# PUBLIC: Add this so that this library will be exported under absl:: (see Note). +# PUBLIC: Add this so that this library will be exported under absl:: # Also in IDE, target will appear in Abseil folder while non PUBLIC will be in Abseil/internal. # TESTONLY: When added, this target will only be built if user passes -DABSL_RUN_TESTS=ON to CMake. # # Note: -# By default, absl_cc_library will always create a library named absl_internal_${NAME}, -# and alias target absl::${NAME}. +# By default, absl_cc_library will always create a library named absl_${NAME}, +# and alias target absl::${NAME}. The absl:: form should always be used. # This is to reduce namespace pollution. # # absl_cc_library( @@ -83,11 +83,7 @@ function(absl_cc_library) ) if (NOT ABSL_CC_LIB_TESTONLY OR ABSL_RUN_TESTS) - if (ABSL_CC_LIB_PUBLIC) - set(_NAME "absl_${ABSL_CC_LIB_NAME}") - else() - set(_NAME "absl_internal_${ABSL_CC_LIB_NAME}") - endif() + set(_NAME "absl_${ABSL_CC_LIB_NAME}") # Check if this is a header-only library # Note that as of February 2019, many popular OS's (for example, Ubuntu diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 19c504583d16..804f62a0bffa 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -326,7 +326,7 @@ cc_library( name = "spinlock_benchmark_common", testonly = 1, srcs = ["internal/spinlock_benchmark.cc"], - copts = ABSL_DEFAULT_COPTS, + copts = ABSL_TEST_COPTS, visibility = [ "//absl/base:__pkg__", ], diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt index f2bacb23b294..d8a311c2f1fe 100644 --- a/absl/base/CMakeLists.txt +++ b/absl/base/CMakeLists.txt @@ -241,7 +241,7 @@ absl_cc_test( "throw_delegate_test.cc" DEPS absl::base - absl_internal_throw_delegate + absl::throw_delegate gtest_main ) diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index db0bb823b1a1..9e79cb38c363 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -135,14 +135,14 @@ TEST(BitMask, WithShift) { } TEST(BitMask, LeadingTrailing) { - EXPECT_EQ((BitMask<uint32_t, 16>(0b0001101001000000).LeadingZeros()), 3); - EXPECT_EQ((BitMask<uint32_t, 16>(0b0001101001000000).TrailingZeros()), 6); + EXPECT_EQ((BitMask<uint32_t, 16>(0x00001a40).LeadingZeros()), 3); + EXPECT_EQ((BitMask<uint32_t, 16>(0x00001a40).TrailingZeros()), 6); - EXPECT_EQ((BitMask<uint32_t, 16>(0b0000000000000001).LeadingZeros()), 15); - EXPECT_EQ((BitMask<uint32_t, 16>(0b0000000000000001).TrailingZeros()), 0); + EXPECT_EQ((BitMask<uint32_t, 16>(0x00000001).LeadingZeros()), 15); + EXPECT_EQ((BitMask<uint32_t, 16>(0x00000001).TrailingZeros()), 0); - EXPECT_EQ((BitMask<uint32_t, 16>(0b1000000000000000).LeadingZeros()), 0); - EXPECT_EQ((BitMask<uint32_t, 16>(0b1000000000000000).TrailingZeros()), 15); + EXPECT_EQ((BitMask<uint32_t, 16>(0x00008000).LeadingZeros()), 0); + EXPECT_EQ((BitMask<uint32_t, 16>(0x00008000).TrailingZeros()), 15); EXPECT_EQ((BitMask<uint64_t, 8, 3>(0x0000008080808000).LeadingZeros()), 3); EXPECT_EQ((BitMask<uint64_t, 8, 3>(0x0000008080808000).TrailingZeros()), 1); diff --git a/absl/strings/numbers_test.cc b/absl/strings/numbers_test.cc index b7b03ff03b4e..ca2ee485d84e 100644 --- a/absl/strings/numbers_test.cc +++ b/absl/strings/numbers_test.cc @@ -785,7 +785,7 @@ void ExhaustiveFloat(uint32_t cases, R&& runnable) { if (iters_per_float == 0) iters_per_float = 1; for (float f : floats) { if (f == last) continue; - float testf = nextafter(last, std::numeric_limits<float>::max()); + float testf = std::nextafter(last, std::numeric_limits<float>::max()); runnable(testf); runnable(-testf); last = testf; @@ -799,7 +799,7 @@ void ExhaustiveFloat(uint32_t cases, R&& runnable) { last = testf; } } - testf = nextafter(f, 0.0f); + testf = std::nextafter(f, 0.0f); if (testf > last) { runnable(testf); runnable(-testf); diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel index ac0190415dc3..5e69847e65ec 100644 --- a/absl/synchronization/BUILD.bazel +++ b/absl/synchronization/BUILD.bazel @@ -178,7 +178,7 @@ cc_library( name = "mutex_benchmark_common", testonly = 1, srcs = ["mutex_benchmark.cc"], - copts = ABSL_DEFAULT_COPTS, + copts = ABSL_TEST_COPTS, visibility = [ "//absl/synchronization:__pkg__", ], diff --git a/absl/types/optional.h b/absl/types/optional.h index a86dea92c4ac..c0488797adaa 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -513,10 +513,11 @@ class optional : private optional_internal::optional_data<T>, // the arguments `std::forward<Args>(args)...` within the `optional`. // (The `in_place_t` is a tag used to indicate that the contained object // should be constructed in-place.) - // - // TODO(absl-team): Add std::is_constructible<T, Args&&...> SFINAE. - template <typename... Args> - constexpr explicit optional(in_place_t, Args&&... args) + template <typename InPlaceT, typename... Args, + absl::enable_if_t<absl::conjunction< + std::is_same<InPlaceT, in_place_t>, + std::is_constructible<T, Args&&...> >::value>* = nullptr> + constexpr explicit optional(InPlaceT, Args&&... args) : data_base(in_place_t(), absl::forward<Args>(args)...) {} // Constructs a non-empty `optional` direct-initialized value of type `T` from diff --git a/absl/types/optional_test.cc b/absl/types/optional_test.cc index b93aa98e3010..68842abb20e5 100644 --- a/absl/types/optional_test.cc +++ b/absl/types/optional_test.cc @@ -157,6 +157,16 @@ struct NonMovable { NonMovable& operator=(NonMovable&&) = delete; }; +struct NoDefault { + NoDefault() = delete; + NoDefault(const NoDefault&) {} + NoDefault& operator=(const NoDefault&) { return *this; } +}; + +struct ConvertsFromInPlaceT { + ConvertsFromInPlaceT(absl::in_place_t) {} // NOLINT +}; + TEST(optionalTest, DefaultConstructor) { absl::optional<int> empty; EXPECT_FALSE(empty); @@ -337,16 +347,18 @@ TEST(optionalTest, InPlaceConstructor) { static_assert((*opt2).x == ConstexprType::kCtorInitializerList, ""); #endif - // TODO(absl-team): uncomment these when std::is_constructible<T, Args&&...> - // SFINAE is added to optional::optional(absl::in_place_t, Args&&...). - // struct I { - // I(absl::in_place_t); - // }; + EXPECT_FALSE((std::is_constructible<absl::optional<ConvertsFromInPlaceT>, + absl::in_place_t>::value)); + EXPECT_FALSE((std::is_constructible<absl::optional<ConvertsFromInPlaceT>, + const absl::in_place_t&>::value)); + EXPECT_TRUE( + (std::is_constructible<absl::optional<ConvertsFromInPlaceT>, + absl::in_place_t, absl::in_place_t>::value)); - // EXPECT_FALSE((std::is_constructible<absl::optional<I>, - // absl::in_place_t>::value)); - // EXPECT_FALSE((std::is_constructible<absl::optional<I>, const - // absl::in_place_t&>::value)); + EXPECT_FALSE((std::is_constructible<absl::optional<NoDefault>, + absl::in_place_t>::value)); + EXPECT_FALSE((std::is_constructible<absl::optional<NoDefault>, + absl::in_place_t&&>::value)); } // template<U=T> optional(U&&); @@ -1624,4 +1636,27 @@ TEST(optionalTest, AssignmentConstraints) { EXPECT_TRUE(absl::is_copy_assignable<absl::optional<AnyLike>>::value); } +struct NestedClassBug { + struct Inner { + bool dummy = false; + }; + absl::optional<Inner> value; +}; + +TEST(optionalTest, InPlaceTSFINAEBug) { + NestedClassBug b; + ((void)b); + using Inner = NestedClassBug::Inner; + + EXPECT_TRUE((std::is_default_constructible<Inner>::value)); + EXPECT_TRUE((std::is_constructible<Inner>::value)); + EXPECT_TRUE( + (std::is_constructible<absl::optional<Inner>, absl::in_place_t>::value)); + + absl::optional<Inner> o(absl::in_place); + EXPECT_TRUE(o.has_value()); + o.emplace(); + EXPECT_TRUE(o.has_value()); +} + } // namespace |