From 04d8afe7a3b36b57f6497c60dc6184e9dfeb85c1 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 19 Jan 2024 07:53:03 -0800 Subject: Remove code pieces for no longer supported MSVC versions. The current support policy is `_MSC_VER >= 1920`. PiperOrigin-RevId: 599833619 Change-Id: I9cf7393a5b659d1680765e37e0328539ccb870fa --- absl/types/optional_test.cc | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'absl/types') diff --git a/absl/types/optional_test.cc b/absl/types/optional_test.cc index 5da297b0..a4daa799 100644 --- a/absl/types/optional_test.cc +++ b/absl/types/optional_test.cc @@ -994,25 +994,6 @@ TEST(optionalTest, PointerStuff) { #endif #endif -// MSVC has a bug with "cv-qualifiers in class construction", fixed in 2017. See -// https://docs.microsoft.com/en-us/cpp/cpp-conformance-improvements-2017#bug-fixes -// The compiler some incorrectly ignores the cv-qualifier when generating a -// class object via a constructor call. For example: -// -// class optional { -// constexpr T&& value() &&; -// constexpr const T&& value() const &&; -// } -// -// using COI = const absl::optional; -// static_assert(2 == COI(2).value(), ""); // const && -// -// This should invoke the "const &&" overload but since it ignores the const -// qualifier it finds the "&&" overload the best candidate. -#if defined(_MSC_VER) && _MSC_VER < 1910 -#define ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG -#endif - TEST(optionalTest, Value) { using O = absl::optional; using CO = const absl::optional; @@ -1032,8 +1013,7 @@ TEST(optionalTest, Value) { EXPECT_EQ("c&", TypeQuals(clvalue.value())); EXPECT_EQ("c&", TypeQuals(lvalue_c.value())); EXPECT_EQ("&&", TypeQuals(O(absl::in_place, "xvalue").value())); -#if !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG) && \ - !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG) +#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG EXPECT_EQ("c&&", TypeQuals(CO(absl::in_place, "cxvalue").value())); #endif EXPECT_EQ("c&&", TypeQuals(OC(absl::in_place, "xvalue_c").value())); @@ -1083,8 +1063,7 @@ TEST(optionalTest, DerefOperator) { EXPECT_EQ("&", TypeQuals(*lvalue)); EXPECT_EQ("c&", TypeQuals(*clvalue)); EXPECT_EQ("&&", TypeQuals(*O(absl::in_place, "xvalue"))); -#if !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG) && \ - !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG) +#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG EXPECT_EQ("c&&", TypeQuals(*CO(absl::in_place, "cxvalue"))); #endif EXPECT_EQ("c&&", TypeQuals(*OC(absl::in_place, "xvalue_c"))); @@ -1117,11 +1096,9 @@ TEST(optionalTest, ValueOr) { constexpr absl::optional copt_empty, copt_set = {1.2}; static_assert(42.0 == copt_empty.value_or(42), ""); static_assert(1.2 == copt_set.value_or(42), ""); -#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG using COD = const absl::optional; static_assert(42.0 == COD().value_or(42), ""); static_assert(1.2 == COD(1.2).value_or(42), ""); -#endif } // make_optional cannot be constexpr until C++17 -- cgit v1.2.3 From f7d2b13ef2466a5a3b7bcc535c49d3962a5c89f9 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 22 Jan 2024 09:09:23 -0800 Subject: Remove code pieces for no longer supported GCC versions. The minimum supported version today is GCC 7 (`__GNUC__ >= 7`). PiperOrigin-RevId: 600475215 Change-Id: I1aa46384f1e75f268649a48dbe2b42f3475bb07f --- absl/base/config.h | 8 ++------ absl/container/internal/compressed_tuple_test.cc | 2 -- absl/container/internal/hash_policy_testing.h | 3 +-- absl/flags/flag_test.cc | 8 -------- absl/types/optional_test.cc | 22 +--------------------- 5 files changed, 4 insertions(+), 39 deletions(-) (limited to 'absl/types') diff --git a/absl/base/config.h b/absl/base/config.h index 0fb66927..5fa9f0ef 100644 --- a/absl/base/config.h +++ b/absl/base/config.h @@ -379,9 +379,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #define ABSL_HAVE_EXCEPTIONS 1 #endif // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions) // Handle remaining special cases and default to exceptions being supported. -#elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \ - !(ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0) && \ - !defined(__cpp_exceptions)) && \ +#elif !(defined(__GNUC__) && !defined(__cpp_exceptions)) && \ !(defined(_MSC_VER) && !defined(_CPPUNWIND)) #define ABSL_HAVE_EXCEPTIONS 1 #endif @@ -902,9 +900,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || #error ABSL_INTERNAL_HAS_CXA_DEMANGLE cannot be directly set #elif defined(OS_ANDROID) && (defined(__i386__) || defined(__x86_64__)) #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 0 -#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && \ - (__GNUC__ >= 4 || (__GNUC__ >= 3 && __GNUC_MINOR__ >= 4)) && \ - !defined(__mips__) +#elif defined(__GNUC__) && !defined(__mips__) #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 1 #elif defined(__clang__) && !defined(_MSC_VER) #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 1 diff --git a/absl/container/internal/compressed_tuple_test.cc b/absl/container/internal/compressed_tuple_test.cc index 74111f97..da07baab 100644 --- a/absl/container/internal/compressed_tuple_test.cc +++ b/absl/container/internal/compressed_tuple_test.cc @@ -358,7 +358,6 @@ TEST(CompressedTupleTest, Constexpr) { EXPECT_EQ(x2, 5); EXPECT_EQ(x3, CallType::kConstRef); -#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 constexpr CompressedTuple, TrivialStruct, int> trivial = {}; constexpr CallType trivial0 = trivial.get<0>().value(); constexpr int trivial1 = trivial.get<1>().value(); @@ -367,7 +366,6 @@ TEST(CompressedTupleTest, Constexpr) { EXPECT_EQ(trivial0, CallType::kConstRef); EXPECT_EQ(trivial1, 0); EXPECT_EQ(trivial2, 0); -#endif constexpr CompressedTuple, NonTrivialStruct, absl::optional> non_trivial = {}; diff --git a/absl/container/internal/hash_policy_testing.h b/absl/container/internal/hash_policy_testing.h index 01c40d2e..66bb12ec 100644 --- a/absl/container/internal/hash_policy_testing.h +++ b/absl/container/internal/hash_policy_testing.h @@ -174,8 +174,7 @@ ABSL_NAMESPACE_END // From GCC-4.9 Changelog: (src: https://gcc.gnu.org/gcc-4.9/changes.html) // "the unordered associative containers in and // meet the allocator-aware container requirements;" -#if (defined(__GLIBCXX__) && __GLIBCXX__ <= 20140425 ) || \ -( __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 9 )) +#if defined(__GLIBCXX__) && __GLIBCXX__ <= 20140425 #define ABSL_UNORDERED_SUPPORTS_ALLOC_CTORS 0 #else #define ABSL_UNORDERED_SUPPORTS_ALLOC_CTORS 1 diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc index 8d14ba8d..53ad4635 100644 --- a/absl/flags/flag_test.cc +++ b/absl/flags/flag_test.cc @@ -1044,13 +1044,7 @@ TEST_F(FlagTest, MacroWithinAbslFlag) { // -------------------------------------------------------------------- -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5 -#define ABSL_SKIP_OPTIONAL_BOOL_TEST_DUE_TO_GCC_BUG -#endif - -#ifndef ABSL_SKIP_OPTIONAL_BOOL_TEST_DUE_TO_GCC_BUG ABSL_FLAG(absl::optional, optional_bool, absl::nullopt, "help"); -#endif ABSL_FLAG(absl::optional, optional_int, {}, "help"); ABSL_FLAG(absl::optional, optional_double, 9.3, "help"); ABSL_FLAG(absl::optional, optional_string, absl::nullopt, "help"); @@ -1064,7 +1058,6 @@ ABSL_FLAG(std::optional, std_optional_int64, std::nullopt, "help"); namespace { -#ifndef ABSL_SKIP_OPTIONAL_BOOL_TEST_DUE_TO_GCC_BUG TEST_F(FlagTest, TestOptionalBool) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_bool).has_value()); EXPECT_EQ(absl::GetFlag(FLAGS_optional_bool), absl::nullopt); @@ -1083,7 +1076,6 @@ TEST_F(FlagTest, TestOptionalBool) { } // -------------------------------------------------------------------- -#endif TEST_F(FlagTest, TestOptionalInt) { EXPECT_FALSE(absl::GetFlag(FLAGS_optional_int).has_value()); diff --git a/absl/types/optional_test.cc b/absl/types/optional_test.cc index a4daa799..115e20ce 100644 --- a/absl/types/optional_test.cc +++ b/absl/types/optional_test.cc @@ -982,18 +982,6 @@ TEST(optionalTest, PointerStuff) { static_assert((*opt1).x == ConstexprType::kCtorInt, ""); } -// gcc has a bug pre 4.9.1 where it doesn't do correct overload resolution -// when overloads are const-qualified and *this is an raluve. -// Skip that test to make the build green again when using the old compiler. -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59296 is fixed in 4.9.1. -#if defined(__GNUC__) && !defined(__clang__) -#define GCC_VERSION \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#if GCC_VERSION < 40901 -#define ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG -#endif -#endif - TEST(optionalTest, Value) { using O = absl::optional; using CO = const absl::optional; @@ -1006,16 +994,12 @@ TEST(optionalTest, Value) { EXPECT_EQ("lvalue_c", lvalue_c.value()); EXPECT_EQ("xvalue", O(absl::in_place, "xvalue").value()); EXPECT_EQ("xvalue_c", OC(absl::in_place, "xvalue_c").value()); -#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG EXPECT_EQ("cxvalue", CO(absl::in_place, "cxvalue").value()); -#endif EXPECT_EQ("&", TypeQuals(lvalue.value())); EXPECT_EQ("c&", TypeQuals(clvalue.value())); EXPECT_EQ("c&", TypeQuals(lvalue_c.value())); EXPECT_EQ("&&", TypeQuals(O(absl::in_place, "xvalue").value())); -#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG EXPECT_EQ("c&&", TypeQuals(CO(absl::in_place, "cxvalue").value())); -#endif EXPECT_EQ("c&&", TypeQuals(OC(absl::in_place, "xvalue_c").value())); #if !defined(ABSL_VOLATILE_RETURN_TYPES_DEPRECATED) @@ -1039,7 +1023,7 @@ TEST(optionalTest, Value) { // test constexpr value() constexpr absl::optional o1(1); static_assert(1 == o1.value(), ""); // const & -#if !defined(_MSC_VER) && !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG) +#ifndef _MSC_VER using COI = const absl::optional; static_assert(2 == COI(2).value(), ""); // const && #endif @@ -1057,15 +1041,11 @@ TEST(optionalTest, DerefOperator) { EXPECT_EQ("lvalue_c", *lvalue_c); EXPECT_EQ("xvalue", *O(absl::in_place, "xvalue")); EXPECT_EQ("xvalue_c", *OC(absl::in_place, "xvalue_c")); -#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG EXPECT_EQ("cxvalue", *CO(absl::in_place, "cxvalue")); -#endif EXPECT_EQ("&", TypeQuals(*lvalue)); EXPECT_EQ("c&", TypeQuals(*clvalue)); EXPECT_EQ("&&", TypeQuals(*O(absl::in_place, "xvalue"))); -#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG EXPECT_EQ("c&&", TypeQuals(*CO(absl::in_place, "cxvalue"))); -#endif EXPECT_EQ("c&&", TypeQuals(*OC(absl::in_place, "xvalue_c"))); #if !defined(ABSL_VOLATILE_RETURN_TYPES_DEPRECATED) -- cgit v1.2.3 From 19c20d73aacfb32968493bf083574f05e68ea051 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 8 Feb 2024 05:37:45 -0800 Subject: Span: Fixed comment referencing std::span as_writable_bytes() as as_mutable_bytes(). PiperOrigin-RevId: 605288522 Change-Id: Id16ad96b9323c71bd60801a6c8c359f7ff3d320e --- absl/types/span.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'absl/types') diff --git a/absl/types/span.h b/absl/types/span.h index 88cd7595..c183aa88 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -43,7 +43,7 @@ // * A read-only `absl::Span` can be implicitly constructed from an // initializer list. // * `absl::Span` has no `bytes()`, `size_bytes()`, `as_bytes()`, or -// `as_mutable_bytes()` methods +// `as_writable_bytes()` methods // * `absl::Span` has no static extent template parameter, nor constructors // which exist only because of the static extent parameter. // * `absl::Span` has an explicit mutable-reference constructor -- cgit v1.2.3 From d802708117c6ef6b9783efe499b2a2d0d0536c77 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Mon, 11 Mar 2024 09:14:45 -0700 Subject: Replace usages of absl::move, absl::forward, and absl::exchange with their std:: equivalents PiperOrigin-RevId: 614687225 Change-Id: I07421db08ee9c221e561f42e3bf8345fb5321401 --- absl/cleanup/cleanup_test.cc | 2 +- absl/container/internal/btree.h | 4 +- absl/container/internal/compressed_tuple.h | 19 ++-- absl/container/internal/compressed_tuple_test.cc | 5 +- absl/container/internal/layout.h | 2 +- absl/functional/bind_front.h | 5 +- absl/functional/internal/front_binder.h | 18 ++-- absl/types/internal/optional.h | 4 +- absl/types/internal/variant.h | 109 ++++++++++++----------- absl/types/optional.h | 33 ++++--- absl/types/variant.h | 43 ++++----- absl/types/variant_test.cc | 76 ++++++++-------- 12 files changed, 157 insertions(+), 163 deletions(-) (limited to 'absl/types') diff --git a/absl/cleanup/cleanup_test.cc b/absl/cleanup/cleanup_test.cc index 46b88589..72d7ff2a 100644 --- a/absl/cleanup/cleanup_test.cc +++ b/absl/cleanup/cleanup_test.cc @@ -48,7 +48,7 @@ class FunctorClass { explicit FunctorClass(Callback callback) : callback_(std::move(callback)) {} FunctorClass(FunctorClass&& other) - : callback_(absl::exchange(other.callback_, Callback())) {} + : callback_(std::exchange(other.callback_, Callback())) {} FunctorClass(const FunctorClass&) = delete; diff --git a/absl/container/internal/btree.h b/absl/container/internal/btree.h index 91df57a3..fd7860da 100644 --- a/absl/container/internal/btree.h +++ b/absl/container/internal/btree.h @@ -1407,9 +1407,9 @@ class btree { copy_or_move_values_in_order(other); } btree(btree &&other) noexcept - : root_(absl::exchange(other.root_, EmptyNode())), + : root_(std::exchange(other.root_, EmptyNode())), rightmost_(std::move(other.rightmost_)), - size_(absl::exchange(other.size_, 0u)) { + size_(std::exchange(other.size_, 0u)) { other.mutable_rightmost() = EmptyNode(); } btree(btree &&other, const allocator_type &alloc) diff --git a/absl/container/internal/compressed_tuple.h b/absl/container/internal/compressed_tuple.h index 59e70eb2..f05a1fdc 100644 --- a/absl/container/internal/compressed_tuple.h +++ b/absl/container/internal/compressed_tuple.h @@ -87,10 +87,10 @@ struct Storage { constexpr Storage() = default; template explicit constexpr Storage(absl::in_place_t, V&& v) - : value(absl::forward(v)) {} + : value(std::forward(v)) {} constexpr const T& get() const& { return value; } T& get() & { return value; } - constexpr const T&& get() const&& { return absl::move(*this).value; } + constexpr const T&& get() const&& { return std::move(*this).value; } T&& get() && { return std::move(*this).value; } }; @@ -99,12 +99,11 @@ struct ABSL_INTERNAL_COMPRESSED_TUPLE_DECLSPEC Storage : T { constexpr Storage() = default; template - explicit constexpr Storage(absl::in_place_t, V&& v) - : T(absl::forward(v)) {} + explicit constexpr Storage(absl::in_place_t, V&& v) : T(std::forward(v)) {} constexpr const T& get() const& { return *this; } T& get() & { return *this; } - constexpr const T&& get() const&& { return absl::move(*this); } + constexpr const T&& get() const&& { return std::move(*this); } T&& get() && { return std::move(*this); } }; @@ -123,7 +122,7 @@ struct ABSL_INTERNAL_COMPRESSED_TUPLE_DECLSPEC CompressedTupleImpl< constexpr CompressedTupleImpl() = default; template explicit constexpr CompressedTupleImpl(absl::in_place_t, Vs&&... args) - : Storage(absl::in_place, absl::forward(args))... {} + : Storage(absl::in_place, std::forward(args))... {} friend CompressedTuple; }; @@ -135,7 +134,7 @@ struct ABSL_INTERNAL_COMPRESSED_TUPLE_DECLSPEC CompressedTupleImpl< constexpr CompressedTupleImpl() = default; template explicit constexpr CompressedTupleImpl(absl::in_place_t, Vs&&... args) - : Storage(absl::in_place, absl::forward(args))... {} + : Storage(absl::in_place, std::forward(args))... {} friend CompressedTuple; }; @@ -234,8 +233,8 @@ class ABSL_INTERNAL_COMPRESSED_TUPLE_DECLSPEC CompressedTuple bool> = true> explicit constexpr CompressedTuple(First&& first, Vs&&... base) : CompressedTuple::CompressedTupleImpl(absl::in_place, - absl::forward(first), - absl::forward(base)...) {} + std::forward(first), + std::forward(base)...) {} template ElemT& get() & { @@ -254,7 +253,7 @@ class ABSL_INTERNAL_COMPRESSED_TUPLE_DECLSPEC CompressedTuple template constexpr const ElemT&& get() const&& { - return absl::move(*this).StorageT::get(); + return std::move(*this).StorageT::get(); } }; diff --git a/absl/container/internal/compressed_tuple_test.cc b/absl/container/internal/compressed_tuple_test.cc index da07baab..49818fb8 100644 --- a/absl/container/internal/compressed_tuple_test.cc +++ b/absl/container/internal/compressed_tuple_test.cc @@ -16,6 +16,7 @@ #include #include +#include #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -384,8 +385,8 @@ TEST(CompressedTupleTest, Constexpr) { #if defined(__clang__) // An apparent bug in earlier versions of gcc claims these are ambiguous. - constexpr int x2m = absl::move(x.get<2>()).get<0>(); - constexpr CallType x3m = absl::move(x).get<3>().value(); + constexpr int x2m = std::move(x.get<2>()).get<0>(); + constexpr CallType x3m = std::move(x).get<3>().value(); EXPECT_EQ(x2m, 5); EXPECT_EQ(x3m, CallType::kConstMove); #endif diff --git a/absl/container/internal/layout.h b/absl/container/internal/layout.h index a4ba6101..1bf739cc 100644 --- a/absl/container/internal/layout.h +++ b/absl/container/internal/layout.h @@ -706,7 +706,7 @@ class Layout : public internal_layout::LayoutType { template static constexpr PartialType Partial(Sizes&&... sizes) { static_assert(sizeof...(Sizes) <= sizeof...(Ts), ""); - return PartialType(absl::forward(sizes)...); + return PartialType(std::forward(sizes)...); } // Creates a layout with the sizes of all arrays specified. If you know diff --git a/absl/functional/bind_front.h b/absl/functional/bind_front.h index a956eb02..885f24b8 100644 --- a/absl/functional/bind_front.h +++ b/absl/functional/bind_front.h @@ -34,6 +34,8 @@ #include // For std::bind_front. #endif // defined(__cpp_lib_bind_front) && __cpp_lib_bind_front >= 201907L +#include + #include "absl/functional/internal/front_binder.h" #include "absl/utility/utility.h" @@ -182,8 +184,7 @@ template constexpr functional_internal::bind_front_t bind_front( F&& func, BoundArgs&&... args) { return functional_internal::bind_front_t( - absl::in_place, absl::forward(func), - absl::forward(args)...); + absl::in_place, std::forward(func), std::forward(args)...); } #endif // defined(__cpp_lib_bind_front) && __cpp_lib_bind_front >= 201907L diff --git a/absl/functional/internal/front_binder.h b/absl/functional/internal/front_binder.h index 45f52de7..44a54928 100644 --- a/absl/functional/internal/front_binder.h +++ b/absl/functional/internal/front_binder.h @@ -34,8 +34,8 @@ namespace functional_internal { template R Apply(Tuple&& bound, absl::index_sequence, Args&&... free) { return base_internal::invoke( - absl::forward(bound).template get()..., - absl::forward(free)...); + std::forward(bound).template get()..., + std::forward(free)...); } template @@ -48,13 +48,13 @@ class FrontBinder { public: template constexpr explicit FrontBinder(absl::in_place_t, Ts&&... ts) - : bound_args_(absl::forward(ts)...) {} + : bound_args_(std::forward(ts)...) {} template > R operator()(FreeArgs&&... free_args) & { return functional_internal::Apply(bound_args_, Idx(), - absl::forward(free_args)...); + std::forward(free_args)...); } template > R operator()(FreeArgs&&... free_args) const& { return functional_internal::Apply(bound_args_, Idx(), - absl::forward(free_args)...); + std::forward(free_args)...); } template (absl::move(bound_args_), Idx(), - absl::forward(free_args)...); + return functional_internal::Apply(std::move(bound_args_), Idx(), + std::forward(free_args)...); } template (absl::move(bound_args_), Idx(), - absl::forward(free_args)...); + return functional_internal::Apply(std::move(bound_args_), Idx(), + std::forward(free_args)...); } }; diff --git a/absl/types/internal/optional.h b/absl/types/internal/optional.h index a96d260a..5731a5bc 100644 --- a/absl/types/internal/optional.h +++ b/absl/types/internal/optional.h @@ -81,7 +81,7 @@ class optional_data_dtor_base { template constexpr explicit optional_data_dtor_base(in_place_t, Args&&... args) - : engaged_(true), data_(absl::forward(args)...) {} + : engaged_(true), data_(std::forward(args)...) {} ~optional_data_dtor_base() { destruct(); } }; @@ -110,7 +110,7 @@ class optional_data_dtor_base { template constexpr explicit optional_data_dtor_base(in_place_t, Args&&... args) - : engaged_(true), data_(absl::forward(args)...) {} + : engaged_(true), data_(std::forward(args)...) {} }; template diff --git a/absl/types/internal/variant.h b/absl/types/internal/variant.h index 263d7b09..40f57c40 100644 --- a/absl/types/internal/variant.h +++ b/absl/types/internal/variant.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "absl/base/config.h" #include "absl/base/internal/identity.h" @@ -214,7 +215,7 @@ constexpr ReturnType call_with_indices(FunctionObject&& function) { std::is_same()( SizeT()...))>::value, "Not all visitation overloads have the same return type."); - return absl::forward(function)(SizeT()...); + return std::forward(function)(SizeT()...); } template @@ -284,7 +285,7 @@ struct UnreachableSwitchCase { assert(false); // NOLINT // Hack to silence potential no return warning -- cause an infinite loop. - return Run(absl::forward(op)); + return Run(std::forward(op)); #endif // Checks for __builtin_unreachable } }; @@ -292,7 +293,7 @@ struct UnreachableSwitchCase { template struct ReachableSwitchCase { static VisitIndicesResultT Run(Op&& op) { - return absl::base_internal::invoke(absl::forward(op), SizeT()); + return absl::base_internal::invoke(std::forward(op), SizeT()); } }; @@ -357,74 +358,74 @@ struct VisitIndicesSwitch { static VisitIndicesResultT Run(Op&& op, std::size_t i) { switch (i) { case 0: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 1: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 2: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 3: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 4: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 5: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 6: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 7: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 8: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 9: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 10: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 11: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 12: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 13: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 14: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 15: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 16: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 17: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 18: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 19: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 20: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 21: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 22: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 23: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 24: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 25: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 26: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 27: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 28: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 29: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 30: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 31: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); case 32: - return PickCase::Run(absl::forward(op)); + return PickCase::Run(std::forward(op)); default: ABSL_ASSERT(i == variant_npos); - return absl::base_internal::invoke(absl::forward(op), NPos()); + return absl::base_internal::invoke(std::forward(op), NPos()); } } }; @@ -437,7 +438,7 @@ struct VisitIndicesFallback { MakeVisitationMatrix, Op, index_sequence<(EndIndices + 1)...>, index_sequence<>>::Run(), - (indices + 1)...)(absl::forward(op)); + (indices + 1)...)(std::forward(op)); } }; @@ -489,7 +490,7 @@ struct VisitIndicesVariadicImpl, EndIndices...> { VisitIndicesResultT operator()( SizeT /*index*/) && { return base_internal::invoke( - absl::forward(op), + std::forward(op), SizeT::value - std::size_t{1}>()...); } @@ -501,7 +502,7 @@ struct VisitIndicesVariadicImpl, EndIndices...> { static VisitIndicesResultT Run(Op&& op, SizeType... i) { return VisitIndicesSwitch::value>::Run( - FlattenedOp{absl::forward(op)}, + FlattenedOp{std::forward(op)}, FlattenIndices<(EndIndices + std::size_t{1})...>::Run( (i + std::size_t{1})...)); } @@ -612,7 +613,7 @@ struct VariantCoreAccess { TypedThrowBadVariantAccess>(); } - return Access(absl::forward(self)); + return Access(std::forward(self)); } // The implementation of the move-assignment operation for a variant. @@ -684,7 +685,7 @@ struct VariantCoreAccess { void operator()(SizeT /*old_i*/ ) const { - Access(*left) = absl::forward(other); + Access(*left) = std::forward(other); } template @@ -695,13 +696,13 @@ struct VariantCoreAccess { if (std::is_nothrow_constructible::value || !std::is_nothrow_move_constructible::value) { left->template emplace( - absl::forward(other)); + std::forward(other)); } else { // the standard says "equivalent to // operator=(variant(std::forward(t)))", but we use `emplace` here // because the variant's move assignment operator could be deleted. left->template emplace( - New(absl::forward(other))); + New(std::forward(other))); } } @@ -712,7 +713,7 @@ struct VariantCoreAccess { template static ConversionAssignVisitor MakeConversionAssignVisitor(Left* left, QualifiedNew&& qual) { - return {left, absl::forward(qual)}; + return {left, std::forward(qual)}; } // Backend for operations for `emplace()` which destructs `*self` then @@ -723,7 +724,7 @@ struct VariantCoreAccess { Destroy(*self); using New = typename absl::variant_alternative::type; New* const result = ::new (static_cast(&self->state_)) - New(absl::forward(args)...); + New(std::forward(args)...); self->index_ = NewIndex; return *result; } @@ -919,9 +920,9 @@ struct PerformVisitation { Is, QualifiedVariants>...)>>::value, "All visitation overloads must have the same return type."); return absl::base_internal::invoke( - absl::forward(op), + std::forward(op), VariantCoreAccess::Access( - absl::forward(std::get(variant_tup)))...); + std::forward(std::get(variant_tup)))...); } template @@ -969,11 +970,11 @@ union Union { template explicit constexpr Union(EmplaceTag<0>, P&&... args) - : head(absl::forward

(args)...) {} + : head(std::forward

(args)...) {} template explicit constexpr Union(EmplaceTag, P&&... args) - : tail(EmplaceTag{}, absl::forward

(args)...) {} + : tail(EmplaceTag{}, std::forward

(args)...) {} Head head; TailUnion tail; @@ -1001,11 +1002,11 @@ union DestructibleUnionImpl { template explicit constexpr DestructibleUnionImpl(EmplaceTag<0>, P&&... args) - : head(absl::forward

(args)...) {} + : head(std::forward

(args)...) {} template explicit constexpr DestructibleUnionImpl(EmplaceTag, P&&... args) - : tail(EmplaceTag{}, absl::forward

(args)...) {} + : tail(EmplaceTag{}, std::forward

(args)...) {} ~DestructibleUnionImpl() {} @@ -1036,7 +1037,7 @@ class VariantStateBase { template explicit constexpr VariantStateBase(EmplaceTag tag, P&&... args) - : state_(tag, absl::forward

(args)...), index_(I) {} + : state_(tag, std::forward

(args)...), index_(I) {} explicit constexpr VariantStateBase(NoopConstructorTag) : state_(NoopConstructorTag()), index_(variant_npos) {} @@ -1321,7 +1322,7 @@ class VariantMoveBaseNontrivial : protected VariantStateBaseDestructor { using Alternative = typename absl::variant_alternative>::type; ::new (static_cast(&self->state_)) Alternative( - variant_internal::AccessUnion(absl::move(other->state_), i)); + variant_internal::AccessUnion(std::move(other->state_), i)); } void operator()(SizeT /*i*/) const {} diff --git a/absl/types/optional.h b/absl/types/optional.h index 395fe62f..cf7249cb 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -151,7 +151,7 @@ class optional : private optional_internal::optional_data, std::is_same, std::is_constructible >::value>* = nullptr> constexpr explicit optional(InPlaceT, Args&&... args) - : data_base(in_place_t(), absl::forward(args)...) {} + : data_base(in_place_t(), std::forward(args)...) {} // Constructs a non-empty `optional` direct-initialized value of type `T` from // the arguments of an initializer_list and `std::forward(args)...`. @@ -162,8 +162,7 @@ class optional : private optional_internal::optional_data, T, std::initializer_list&, Args&&...>::value>::type> constexpr explicit optional(in_place_t, std::initializer_list il, Args&&... args) - : data_base(in_place_t(), il, absl::forward(args)...) { - } + : data_base(in_place_t(), il, std::forward(args)...) {} // Value constructor (implicit) template < @@ -176,21 +175,21 @@ class optional : private optional_internal::optional_data, std::is_convertible, std::is_constructible >::value, bool>::type = false> - constexpr optional(U&& v) : data_base(in_place_t(), absl::forward(v)) {} + constexpr optional(U&& v) : data_base(in_place_t(), std::forward(v)) {} // Value constructor (explicit) template < typename U = T, typename std::enable_if< absl::conjunction::type>>, + in_place_t, typename std::decay::type> >, absl::negation, typename std::decay::type>>, - absl::negation>, - std::is_constructible>::value, + optional, typename std::decay::type> >, + absl::negation >, + std::is_constructible >::value, bool>::type = false> explicit constexpr optional(U&& v) - : data_base(in_place_t(), absl::forward(v)) {} + : data_base(in_place_t(), std::forward(v)) {} // Converting copy constructor (implicit) template , return reference(); } constexpr const T&& operator*() const&& ABSL_ATTRIBUTE_LIFETIME_BOUND { - return ABSL_HARDENING_ASSERT(this->engaged_), absl::move(reference()); + return ABSL_HARDENING_ASSERT(this->engaged_), std::move(reference()); } T&& operator*() && ABSL_ATTRIBUTE_LIFETIME_BOUND { ABSL_HARDENING_ASSERT(this->engaged_); @@ -492,7 +491,7 @@ class optional : private optional_internal::optional_data, } constexpr const T&& value() const&& ABSL_ATTRIBUTE_LIFETIME_BOUND { // NOLINT(build/c++11) - return absl::move( + return std::move( static_cast(*this) ? reference() : (optional_internal::throw_bad_optional_access(), reference())); @@ -511,9 +510,8 @@ class optional : private optional_internal::optional_data, "optional::value_or: T must be copy constructible"); static_assert(std::is_convertible::value, "optional::value_or: U must be convertible to T"); - return static_cast(*this) - ? **this - : static_cast(absl::forward(v)); + return static_cast(*this) ? **this + : static_cast(std::forward(v)); } template T value_or(U&& v) && { // NOLINT(build/c++11) @@ -573,19 +571,18 @@ void swap(optional& a, optional& b) noexcept(noexcept(a.swap(b))) { // static_assert(opt.value() == 1, ""); template constexpr optional::type> make_optional(T&& v) { - return optional::type>(absl::forward(v)); + return optional::type>(std::forward(v)); } template constexpr optional make_optional(Args&&... args) { - return optional(in_place_t(), absl::forward(args)...); + return optional(in_place_t(), std::forward(args)...); } template constexpr optional make_optional(std::initializer_list il, Args&&... args) { - return optional(in_place_t(), il, - absl::forward(args)...); + return optional(in_place_t(), il, std::forward(args)...); } // Relational operators [optional.relops] diff --git a/absl/types/variant.h b/absl/types/variant.h index ac93464b..56a7e05e 100644 --- a/absl/types/variant.h +++ b/absl/types/variant.h @@ -303,11 +303,10 @@ constexpr T& get(variant& v) { // NOLINT } // Overload for getting a variant's rvalue by type. -// Note: `absl::move()` is required to allow use of constexpr in C++11. template constexpr T&& get(variant&& v) { return variant_internal::VariantCoreAccess::CheckedAccess< - variant_internal::IndexOf::value>(absl::move(v)); + variant_internal::IndexOf::value>(std::move(v)); } // Overload for getting a variant's const lvalue by type. @@ -318,11 +317,10 @@ constexpr const T& get(const variant& v) { } // Overload for getting a variant's const rvalue by type. -// Note: `absl::move()` is required to allow use of constexpr in C++11. template constexpr const T&& get(const variant&& v) { return variant_internal::VariantCoreAccess::CheckedAccess< - variant_internal::IndexOf::value>(absl::move(v)); + variant_internal::IndexOf::value>(std::move(v)); } // Overload for getting a variant's lvalue by index. @@ -333,11 +331,10 @@ constexpr variant_alternative_t>& get( } // Overload for getting a variant's rvalue by index. -// Note: `absl::move()` is required to allow use of constexpr in C++11. template constexpr variant_alternative_t>&& get( variant&& v) { - return variant_internal::VariantCoreAccess::CheckedAccess(absl::move(v)); + return variant_internal::VariantCoreAccess::CheckedAccess(std::move(v)); } // Overload for getting a variant's const lvalue by index. @@ -348,11 +345,10 @@ constexpr const variant_alternative_t>& get( } // Overload for getting a variant's const rvalue by index. -// Note: `absl::move()` is required to allow use of constexpr in C++11. template constexpr const variant_alternative_t>&& get( const variant&& v) { - return variant_internal::VariantCoreAccess::CheckedAccess(absl::move(v)); + return variant_internal::VariantCoreAccess::CheckedAccess(std::move(v)); } // get_if() @@ -432,8 +428,8 @@ variant_internal::VisitResult visit(Visitor&& vis, return variant_internal:: VisitIndices >::value...>::Run( variant_internal::PerformVisitation{ - std::forward_as_tuple(absl::forward(vars)...), - absl::forward(vis)}, + std::forward_as_tuple(std::forward(vars)...), + std::forward(vis)}, vars.index()...); } @@ -504,13 +500,12 @@ class variant : private variant_internal::VariantBase { class T, std::size_t I = std::enable_if< variant_internal::IsNeitherSelfNorInPlace>::value, - variant_internal::IndexOfConstructedType>::type::value, + absl::decay_t >::value, + variant_internal::IndexOfConstructedType >::type::value, class Tj = absl::variant_alternative_t, - absl::enable_if_t::value>* = - nullptr> + absl::enable_if_t::value>* = nullptr> constexpr variant(T&& t) noexcept(std::is_nothrow_constructible::value) - : Base(variant_internal::EmplaceTag(), absl::forward(t)) {} + : Base(variant_internal::EmplaceTag(), std::forward(t)) {} // Constructs a variant of an alternative type from the arguments through // direct-initialization. @@ -524,7 +519,7 @@ class variant : private variant_internal::VariantBase { constexpr explicit variant(in_place_type_t, Args&&... args) : Base(variant_internal::EmplaceTag< variant_internal::UnambiguousIndexOf::value>(), - absl::forward(args)...) {} + std::forward(args)...) {} // Constructs a variant of an alternative type from an initializer list // and other arguments through direct-initialization. @@ -539,7 +534,7 @@ class variant : private variant_internal::VariantBase { Args&&... args) : Base(variant_internal::EmplaceTag< variant_internal::UnambiguousIndexOf::value>(), - il, absl::forward(args)...) {} + il, std::forward(args)...) {} // Constructs a variant of an alternative type from a provided index, // through value-initialization using the provided forwarded arguments. @@ -548,7 +543,7 @@ class variant : private variant_internal::VariantBase { variant_internal::VariantAlternativeSfinaeT, Args...>::value>::type* = nullptr> constexpr explicit variant(in_place_index_t, Args&&... args) - : Base(variant_internal::EmplaceTag(), absl::forward(args)...) {} + : Base(variant_internal::EmplaceTag(), std::forward(args)...) {} // Constructs a variant of an alternative type from a provided index, // through value-initialization of an initializer list and the provided @@ -560,7 +555,7 @@ class variant : private variant_internal::VariantBase { constexpr explicit variant(in_place_index_t, std::initializer_list il, Args&&... args) : Base(variant_internal::EmplaceTag(), il, - absl::forward(args)...) {} + std::forward(args)...) {} // Destructors @@ -595,7 +590,7 @@ class variant : private variant_internal::VariantBase { std::is_nothrow_constructible::value) { variant_internal::VisitIndices::Run( variant_internal::VariantCoreAccess::MakeConversionAssignVisitor( - this, absl::forward(t)), + this, std::forward(t)), index()); return *this; @@ -623,7 +618,7 @@ class variant : private variant_internal::VariantBase { T& emplace(Args&&... args) { return variant_internal::VariantCoreAccess::Replace< variant_internal::UnambiguousIndexOf::value>( - this, absl::forward(args)...); + this, std::forward(args)...); } // Constructs a value of the given alternative type T within the variant using @@ -644,7 +639,7 @@ class variant : private variant_internal::VariantBase { T& emplace(std::initializer_list il, Args&&... args) { return variant_internal::VariantCoreAccess::Replace< variant_internal::UnambiguousIndexOf::value>( - this, il, absl::forward(args)...); + this, il, std::forward(args)...); } // Destroys the current value of the variant (provided that @@ -663,7 +658,7 @@ class variant : private variant_internal::VariantBase { Args...>::value>::type* = nullptr> absl::variant_alternative_t& emplace(Args&&... args) { return variant_internal::VariantCoreAccess::Replace( - this, absl::forward(args)...); + this, std::forward(args)...); } // Destroys the current value of the variant (provided that @@ -681,7 +676,7 @@ class variant : private variant_internal::VariantBase { absl::variant_alternative_t& emplace(std::initializer_list il, Args&&... args) { return variant_internal::VariantCoreAccess::Replace( - this, il, absl::forward(args)...); + this, il, std::forward(args)...); } // variant::valueless_by_exception() diff --git a/absl/types/variant_test.cc b/absl/types/variant_test.cc index 4cd5b7a3..91b142ca 100644 --- a/absl/types/variant_test.cc +++ b/absl/types/variant_test.cc @@ -389,7 +389,7 @@ TEST(VariantTest, TestMoveConstruct) { using V = variant, MoveOnly, MoveOnly>; V v(in_place_index<1>, 10); - V v2 = absl::move(v); + V v2 = std::move(v); EXPECT_EQ(10, absl::get<1>(v2).value); } @@ -1209,60 +1209,60 @@ TEST(VariantTest, GetIndex) { Var v(absl::in_place_index<0>, 0); using LValueGetType = decltype(absl::get<0>(v)); - using RValueGetType = decltype(absl::get<0>(absl::move(v))); + using RValueGetType = decltype(absl::get<0>(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<0>(v), 0); - EXPECT_EQ(absl::get<0>(absl::move(v)), 0); + EXPECT_EQ(absl::get<0>(std::move(v)), 0); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get<0>(const_v)); - using ConstRValueGetType = decltype(absl::get<0>(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get<0>(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<0>(const_v), 0); - EXPECT_EQ(absl::get<0>(absl::move(const_v)), 0); + EXPECT_EQ(absl::get<0>(std::move(const_v)), 0); } { Var v = std::string("Hello"); using LValueGetType = decltype(absl::get<1>(v)); - using RValueGetType = decltype(absl::get<1>(absl::move(v))); + using RValueGetType = decltype(absl::get<1>(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<1>(v), "Hello"); - EXPECT_EQ(absl::get<1>(absl::move(v)), "Hello"); + EXPECT_EQ(absl::get<1>(std::move(v)), "Hello"); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get<1>(const_v)); - using ConstRValueGetType = decltype(absl::get<1>(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get<1>(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<1>(const_v), "Hello"); - EXPECT_EQ(absl::get<1>(absl::move(const_v)), "Hello"); + EXPECT_EQ(absl::get<1>(std::move(const_v)), "Hello"); } { Var v = 2.0; using LValueGetType = decltype(absl::get<2>(v)); - using RValueGetType = decltype(absl::get<2>(absl::move(v))); + using RValueGetType = decltype(absl::get<2>(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<2>(v), 2.); - EXPECT_EQ(absl::get<2>(absl::move(v)), 2.); + EXPECT_EQ(absl::get<2>(std::move(v)), 2.); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get<2>(const_v)); - using ConstRValueGetType = decltype(absl::get<2>(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get<2>(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<2>(const_v), 2.); - EXPECT_EQ(absl::get<2>(absl::move(const_v)), 2.); + EXPECT_EQ(absl::get<2>(std::move(const_v)), 2.); } { @@ -1270,20 +1270,20 @@ TEST(VariantTest, GetIndex) { v.emplace<3>(1); using LValueGetType = decltype(absl::get<3>(v)); - using RValueGetType = decltype(absl::get<3>(absl::move(v))); + using RValueGetType = decltype(absl::get<3>(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<3>(v), 1); - EXPECT_EQ(absl::get<3>(absl::move(v)), 1); + EXPECT_EQ(absl::get<3>(std::move(v)), 1); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get<3>(const_v)); - using ConstRValueGetType = decltype(absl::get<3>(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get<3>(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get<3>(const_v), 1); - EXPECT_EQ(absl::get<3>(absl::move(const_v)), 1); // NOLINT + EXPECT_EQ(absl::get<3>(std::move(const_v)), 1); // NOLINT } } @@ -1322,60 +1322,60 @@ TEST(VariantTest, GetType) { Var v = 1; using LValueGetType = decltype(absl::get(v)); - using RValueGetType = decltype(absl::get(absl::move(v))); + using RValueGetType = decltype(absl::get(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get(v), 1); - EXPECT_EQ(absl::get(absl::move(v)), 1); + EXPECT_EQ(absl::get(std::move(v)), 1); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get(const_v)); - using ConstRValueGetType = decltype(absl::get(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get(const_v), 1); - EXPECT_EQ(absl::get(absl::move(const_v)), 1); + EXPECT_EQ(absl::get(std::move(const_v)), 1); } { Var v = std::string("Hello"); using LValueGetType = decltype(absl::get<1>(v)); - using RValueGetType = decltype(absl::get<1>(absl::move(v))); + using RValueGetType = decltype(absl::get<1>(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get(v), "Hello"); - EXPECT_EQ(absl::get(absl::move(v)), "Hello"); + EXPECT_EQ(absl::get(std::move(v)), "Hello"); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get<1>(const_v)); - using ConstRValueGetType = decltype(absl::get<1>(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get<1>(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get(const_v), "Hello"); - EXPECT_EQ(absl::get(absl::move(const_v)), "Hello"); + EXPECT_EQ(absl::get(std::move(const_v)), "Hello"); } { Var v = 2.0; using LValueGetType = decltype(absl::get<2>(v)); - using RValueGetType = decltype(absl::get<2>(absl::move(v))); + using RValueGetType = decltype(absl::get<2>(std::move(v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get(v), 2.); - EXPECT_EQ(absl::get(absl::move(v)), 2.); + EXPECT_EQ(absl::get(std::move(v)), 2.); const Var& const_v = v; using ConstLValueGetType = decltype(absl::get<2>(const_v)); - using ConstRValueGetType = decltype(absl::get<2>(absl::move(const_v))); + using ConstRValueGetType = decltype(absl::get<2>(std::move(const_v))); EXPECT_TRUE((std::is_same::value)); EXPECT_TRUE((std::is_same::value)); EXPECT_EQ(absl::get(const_v), 2.); - EXPECT_EQ(absl::get(absl::move(const_v)), 2.); + EXPECT_EQ(absl::get(std::move(const_v)), 2.); } } @@ -1825,13 +1825,13 @@ TEST(VariantTest, VisitRValue) { int operator()(std::string&&, std::string&&) const { return 3; } // NOLINT }; EXPECT_FALSE(absl::visit(Visitor{}, v)); - EXPECT_TRUE(absl::visit(Visitor{}, absl::move(v))); + EXPECT_TRUE(absl::visit(Visitor{}, std::move(v))); // Also test the variadic overload. EXPECT_EQ(0, absl::visit(Visitor{}, v, v)); - EXPECT_EQ(1, absl::visit(Visitor{}, v, absl::move(v))); - EXPECT_EQ(2, absl::visit(Visitor{}, absl::move(v), v)); - EXPECT_EQ(3, absl::visit(Visitor{}, absl::move(v), absl::move(v))); + EXPECT_EQ(1, absl::visit(Visitor{}, v, std::move(v))); + EXPECT_EQ(2, absl::visit(Visitor{}, std::move(v), v)); + EXPECT_EQ(3, absl::visit(Visitor{}, std::move(v), std::move(v))); } TEST(VariantTest, VisitRValueVisitor) { @@ -1862,12 +1862,12 @@ TEST(VariantTest, VisitResultTypeDifferent) { (std::is_same::value)); EXPECT_TRUE( (std::is_same::value)); + decltype(absl::visit(visitor, std::move(v)))>::value)); EXPECT_TRUE(( std::is_same::value)); EXPECT_TRUE( (std::is_same::value)); + decltype(absl::visit(Visitor{}, std::move(v)))>::value)); } TEST(VariantTest, VisitVariadic) { @@ -2225,7 +2225,7 @@ TEST(VariantTest, TestMoveSemantics) { EXPECT_TRUE(absl::holds_alternative>(v)); // Construct a variant by moving from another variant. - Variant v2(absl::move(v)); + Variant v2(std::move(v)); ASSERT_TRUE(absl::holds_alternative>(v2)); ASSERT_NE(nullptr, absl::get>(v2)); EXPECT_EQ(10, *absl::get>(v2)); @@ -2242,7 +2242,7 @@ TEST(VariantTest, TestMoveSemantics) { EXPECT_EQ("foo", *absl::get>(v)); // Move-assign a variant. - v2 = absl::move(v); + v2 = std::move(v); ASSERT_TRUE(absl::holds_alternative>(v2)); EXPECT_EQ("foo", *absl::get>(v2)); EXPECT_TRUE(absl::holds_alternative>(v)); @@ -2568,7 +2568,7 @@ TEST(VariantTest, TestVectorOfMoveonlyVariant) { vec.push_back(absl::make_unique(42)); vec.emplace_back("Hello"); vec.reserve(3); - auto another_vec = absl::move(vec); + auto another_vec = std::move(vec); // As a sanity check, verify vector contents. ASSERT_EQ(2u, another_vec.size()); EXPECT_EQ(42, *absl::get>(another_vec[0])); -- cgit v1.2.3 From c02bb5f6dae73df83abc0d960ccf5cf3ab00f24c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 2 Apr 2024 07:40:17 -0700 Subject: Add internal traits to absl::Span for lifetimebound detection PiperOrigin-RevId: 621169753 Change-Id: Ib6d7b248e14f29f1f91c24b8e1cf9703962b0e36 --- absl/types/BUILD.bazel | 1 + absl/types/CMakeLists.txt | 1 + absl/types/span.h | 1 + absl/types/span_test.cc | 5 +++++ 4 files changed, 8 insertions(+) (limited to 'absl/types') diff --git a/absl/types/BUILD.bazel b/absl/types/BUILD.bazel index ce8f605b..a86e2c13 100644 --- a/absl/types/BUILD.bazel +++ b/absl/types/BUILD.bazel @@ -138,6 +138,7 @@ cc_test( "//absl/container:fixed_array", "//absl/container:inlined_vector", "//absl/hash:hash_testing", + "//absl/meta:type_traits", "//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/absl/types/CMakeLists.txt b/absl/types/CMakeLists.txt index 92b4ae49..fed532fc 100644 --- a/absl/types/CMakeLists.txt +++ b/absl/types/CMakeLists.txt @@ -138,6 +138,7 @@ absl_cc_test( absl::inlined_vector absl::hash_testing absl::strings + absl::type_traits GTest::gmock_main ) diff --git a/absl/types/span.h b/absl/types/span.h index c183aa88..560e569b 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -185,6 +185,7 @@ class Span { using const_reverse_iterator = std::reverse_iterator; using size_type = size_t; using difference_type = ptrdiff_t; + using absl_internal_is_view = std::true_type; static const size_type npos = ~(size_type(0)); diff --git a/absl/types/span_test.cc b/absl/types/span_test.cc index 29e8681f..e24144dd 100644 --- a/absl/types/span_test.cc +++ b/absl/types/span_test.cc @@ -31,10 +31,15 @@ #include "absl/container/fixed_array.h" #include "absl/container/inlined_vector.h" #include "absl/hash/hash_testing.h" +#include "absl/meta/type_traits.h" #include "absl/strings/str_cat.h" namespace { +static_assert(!absl::type_traits_internal::IsOwner>::value && + absl::type_traits_internal::IsView>::value, + "Span is a view, not an owner"); + MATCHER_P(DataIs, data, absl::StrCat("data() ", negation ? "isn't " : "is ", testing::PrintToString(data))) { -- cgit v1.2.3 From 567ebd0540f4e56d125491e71e2727d8ab5458e0 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 12 Jun 2024 08:13:58 -0700 Subject: Add ABSL_INTERNAL_ATTRIBUTE_VIEW and ABSL_INTERNAL_ATTRIBUTE_OWNER attributes to types in Abseil PiperOrigin-RevId: 642619703 Change-Id: I8d2e423a3c7f40709d0e8c82cac0395c75d601cf --- absl/container/btree_set.h | 1 + absl/container/flat_hash_map.h | 8 +++++--- absl/container/flat_hash_set.h | 3 ++- absl/container/node_hash_map.h | 3 ++- absl/container/node_hash_set.h | 3 ++- absl/strings/string_view.h | 2 +- absl/types/span.h | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) (limited to 'absl/types') diff --git a/absl/container/btree_set.h b/absl/container/btree_set.h index 51dc42b7..97b203a9 100644 --- a/absl/container/btree_set.h +++ b/absl/container/btree_set.h @@ -52,6 +52,7 @@ #ifndef ABSL_CONTAINER_BTREE_SET_H_ #define ABSL_CONTAINER_BTREE_SET_H_ +#include "absl/base/attributes.h" #include "absl/container/internal/btree.h" // IWYU pragma: export #include "absl/container/internal/btree_container.h" // IWYU pragma: export diff --git a/absl/container/flat_hash_map.h b/absl/container/flat_hash_map.h index aa2c5c8c..1c43e92d 100644 --- a/absl/container/flat_hash_map.h +++ b/absl/container/flat_hash_map.h @@ -36,6 +36,7 @@ #include #include "absl/algorithm/container.h" +#include "absl/base/attributes.h" #include "absl/base/macros.h" #include "absl/container/hash_container_defaults.h" #include "absl/container/internal/container_memory.h" @@ -121,9 +122,10 @@ struct FlatHashMapPolicy; template , class Eq = DefaultHashContainerEq, class Allocator = std::allocator>> -class flat_hash_map : public absl::container_internal::raw_hash_map< - absl::container_internal::FlatHashMapPolicy, - Hash, Eq, Allocator> { +class ABSL_INTERNAL_ATTRIBUTE_OWNER flat_hash_map + : public absl::container_internal::raw_hash_map< + absl::container_internal::FlatHashMapPolicy, Hash, Eq, + Allocator> { using Base = typename flat_hash_map::raw_hash_map; public: diff --git a/absl/container/flat_hash_set.h b/absl/container/flat_hash_set.h index e558b071..7b9e0060 100644 --- a/absl/container/flat_hash_set.h +++ b/absl/container/flat_hash_set.h @@ -35,6 +35,7 @@ #include #include "absl/algorithm/container.h" +#include "absl/base/attributes.h" #include "absl/base/macros.h" #include "absl/container/hash_container_defaults.h" #include "absl/container/internal/container_memory.h" @@ -117,7 +118,7 @@ struct FlatHashSetPolicy; template , class Eq = DefaultHashContainerEq, class Allocator = std::allocator> -class flat_hash_set +class ABSL_INTERNAL_ATTRIBUTE_OWNER flat_hash_set : public absl::container_internal::raw_hash_set< absl::container_internal::FlatHashSetPolicy, Hash, Eq, Allocator> { using Base = typename flat_hash_set::raw_hash_set; diff --git a/absl/container/node_hash_map.h b/absl/container/node_hash_map.h index 31beb1da..4bba130d 100644 --- a/absl/container/node_hash_map.h +++ b/absl/container/node_hash_map.h @@ -42,6 +42,7 @@ #include #include "absl/algorithm/container.h" +#include "absl/base/attributes.h" #include "absl/container/hash_container_defaults.h" #include "absl/container/internal/container_memory.h" #include "absl/container/internal/node_slot_policy.h" @@ -116,7 +117,7 @@ class NodeHashMapPolicy; template , class Eq = DefaultHashContainerEq, class Alloc = std::allocator>> -class node_hash_map +class ABSL_INTERNAL_ATTRIBUTE_OWNER node_hash_map : public absl::container_internal::raw_hash_map< absl::container_internal::NodeHashMapPolicy, Hash, Eq, Alloc> { diff --git a/absl/container/node_hash_set.h b/absl/container/node_hash_set.h index deeb49ce..82e4923e 100644 --- a/absl/container/node_hash_set.h +++ b/absl/container/node_hash_set.h @@ -40,6 +40,7 @@ #include #include "absl/algorithm/container.h" +#include "absl/base/attributes.h" #include "absl/container/hash_container_defaults.h" #include "absl/container/internal/container_memory.h" #include "absl/container/internal/node_slot_policy.h" @@ -111,7 +112,7 @@ struct NodeHashSetPolicy; // } template , class Eq = DefaultHashContainerEq, class Alloc = std::allocator> -class node_hash_set +class ABSL_INTERNAL_ATTRIBUTE_OWNER node_hash_set : public absl::container_internal::raw_hash_set< absl::container_internal::NodeHashSetPolicy, Hash, Eq, Alloc> { using Base = typename node_hash_set::raw_hash_set; diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h index b1fb7a10..ff760014 100644 --- a/absl/strings/string_view.h +++ b/absl/strings/string_view.h @@ -159,7 +159,7 @@ ABSL_NAMESPACE_BEGIN // // absl::string_view() == absl::string_view("", 0) // absl::string_view(nullptr, 0) == absl::string_view("abcdef"+6, 0) -class string_view { +class ABSL_INTERNAL_ATTRIBUTE_VIEW string_view { public: using traits_type = std::char_traits; using value_type = char; diff --git a/absl/types/span.h b/absl/types/span.h index 560e569b..a0f80272 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -151,7 +151,7 @@ ABSL_NAMESPACE_BEGIN // int* my_array = new int[10]; // MyRoutine(absl::Span(my_array, 10)); template -class Span { +class ABSL_INTERNAL_ATTRIBUTE_VIEW Span { private: // Used to determine whether a Span can be constructed from a container of // type C. -- cgit v1.2.3 From 7c03b80ef26eef1b34775b035b66a2531d917595 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Thu, 13 Jun 2024 09:28:19 -0700 Subject: Use ABSL_UNREACHABLE() instead of equivalent PiperOrigin-RevId: 643024432 Change-Id: Id07aa18d186291442f7b6f3c68ef8dd6cc20b434 --- absl/types/internal/variant.h | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'absl/types') diff --git a/absl/types/internal/variant.h b/absl/types/internal/variant.h index 40f57c40..4cb15f29 100644 --- a/absl/types/internal/variant.h +++ b/absl/types/internal/variant.h @@ -273,20 +273,7 @@ struct UnreachableSwitchCase { template [[noreturn]] static VisitIndicesResultT Run( Op&& /*ignored*/) { -#if ABSL_HAVE_BUILTIN(__builtin_unreachable) || \ - (defined(__GNUC__) && !defined(__clang__)) - __builtin_unreachable(); -#elif defined(_MSC_VER) - __assume(false); -#else - // Try to use assert of false being identified as an unreachable intrinsic. - // NOTE: We use assert directly to increase chances of exploiting an assume - // intrinsic. - assert(false); // NOLINT - - // Hack to silence potential no return warning -- cause an infinite loop. - return Run(std::forward(op)); -#endif // Checks for __builtin_unreachable + ABSL_UNREACHABLE(); } }; -- cgit v1.2.3