diff options
Diffstat (limited to 'absl/types')
-rw-r--r-- | absl/types/BUILD.bazel | 4 | ||||
-rw-r--r-- | absl/types/CMakeLists.txt | 4 | ||||
-rw-r--r-- | absl/types/any.h | 6 | ||||
-rw-r--r-- | absl/types/any_test.cc | 4 | ||||
-rw-r--r-- | absl/types/compare.h | 22 | ||||
-rw-r--r-- | absl/types/internal/optional.h | 52 | ||||
-rw-r--r-- | absl/types/internal/span.h | 4 | ||||
-rw-r--r-- | absl/types/internal/variant.h | 4 | ||||
-rw-r--r-- | absl/types/optional.h | 28 | ||||
-rw-r--r-- | absl/types/optional_test.cc | 35 | ||||
-rw-r--r-- | absl/types/span.h | 3 | ||||
-rw-r--r-- | absl/types/span_test.cc | 2 |
12 files changed, 56 insertions, 112 deletions
diff --git a/absl/types/BUILD.bazel b/absl/types/BUILD.bazel index bb801012..b57d3b9b 100644 --- a/absl/types/BUILD.bazel +++ b/absl/types/BUILD.bazel @@ -77,8 +77,8 @@ cc_test( ":any", "//absl/base:config", "//absl/base:exception_testing", - "//absl/base:raw_logging_internal", "//absl/container:test_instance_tracker", + "//absl/log", "@com_google_googletest//:gtest_main", ], ) @@ -185,7 +185,7 @@ cc_test( deps = [ ":optional", "//absl/base:config", - "//absl/base:raw_logging_internal", + "//absl/log", "//absl/meta:type_traits", "//absl/strings", "@com_google_googletest//:gtest_main", diff --git a/absl/types/CMakeLists.txt b/absl/types/CMakeLists.txt index 830953ae..c0dcee79 100644 --- a/absl/types/CMakeLists.txt +++ b/absl/types/CMakeLists.txt @@ -68,7 +68,7 @@ absl_cc_test( absl::any absl::config absl::exception_testing - absl::raw_logging_internal + absl::log absl::test_instance_tracker GTest::gmock_main ) @@ -220,7 +220,7 @@ absl_cc_test( DEPS absl::optional absl::config - absl::raw_logging_internal + absl::log absl::strings absl::type_traits GTest::gmock_main diff --git a/absl/types/any.h b/absl/types/any.h index 204da26d..61f071f1 100644 --- a/absl/types/any.h +++ b/absl/types/any.h @@ -53,6 +53,7 @@ #ifndef ABSL_TYPES_ANY_H_ #define ABSL_TYPES_ANY_H_ +#include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/utility/utility.h" @@ -288,7 +289,7 @@ class any { typename T, typename... Args, typename VT = absl::decay_t<T>, absl::enable_if_t<std::is_copy_constructible<VT>::value && std::is_constructible<VT, Args...>::value>* = nullptr> - VT& emplace(Args&&... args) { + VT& emplace(Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { reset(); // NOTE: reset() is required here even in the world of exceptions. Obj<VT>* const object_ptr = new Obj<VT>(in_place, std::forward<Args>(args)...); @@ -312,7 +313,8 @@ class any { absl::enable_if_t<std::is_copy_constructible<VT>::value && std::is_constructible<VT, std::initializer_list<U>&, Args...>::value>* = nullptr> - VT& emplace(std::initializer_list<U> ilist, Args&&... args) { + VT& emplace(std::initializer_list<U> ilist, + Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { reset(); // NOTE: reset() is required here even in the world of exceptions. Obj<VT>* const object_ptr = new Obj<VT>(in_place, ilist, std::forward<Args>(args)...); diff --git a/absl/types/any_test.cc b/absl/types/any_test.cc index d382b927..666ea5b6 100644 --- a/absl/types/any_test.cc +++ b/absl/types/any_test.cc @@ -25,8 +25,8 @@ #include "gtest/gtest.h" #include "absl/base/config.h" #include "absl/base/internal/exception_testing.h" -#include "absl/base/internal/raw_logging.h" #include "absl/container/internal/test_instance_tracker.h" +#include "absl/log/log.h" namespace { using absl::test_internal::CopyableOnlyInstance; @@ -704,7 +704,7 @@ struct BadCopyable { #ifdef ABSL_HAVE_EXCEPTIONS throw BadCopy(); #else - ABSL_RAW_LOG(FATAL, "Bad copy"); + LOG(FATAL) << "Bad copy"; #endif } }; diff --git a/absl/types/compare.h b/absl/types/compare.h index 1a965e97..2b89b69c 100644 --- a/absl/types/compare.h +++ b/absl/types/compare.h @@ -36,6 +36,7 @@ #include <type_traits> #include "absl/base/attributes.h" +#include "absl/base/macros.h" #include "absl/meta/type_traits.h" namespace absl { @@ -45,14 +46,23 @@ namespace compare_internal { using value_type = int8_t; class OnlyLiteralZero { - // A private type which cannot be named to explicitly cast to it. - struct MatchLiteralZero; - public: +#if ABSL_HAVE_ATTRIBUTE(enable_if) + // On clang, we can avoid triggering modernize-use-nullptr by only enabling + // this overload when the value is a compile time integer constant equal to 0. + // + // In c++20, this could be a static_assert in a consteval function. + constexpr OnlyLiteralZero(int n) // NOLINT + __attribute__((enable_if(n == 0, "Only literal `0` is allowed."))) {} +#else // ABSL_HAVE_ATTRIBUTE(enable_if) // Accept only literal zero since it can be implicitly converted to a pointer - // type. nullptr constants will be caught by the other constructor which - // accepts a nullptr_t. - constexpr OnlyLiteralZero(MatchLiteralZero *) noexcept {} // NOLINT + // to member type. nullptr constants will be caught by the other constructor + // which accepts a nullptr_t. + // + // This constructor is not used for clang since it triggers + // modernize-use-nullptr. + constexpr OnlyLiteralZero(int OnlyLiteralZero::*) noexcept {} // NOLINT +#endif // Fails compilation when `nullptr` or integral type arguments other than // `int` are passed. This constructor doesn't accept `int` because literal `0` diff --git a/absl/types/internal/optional.h b/absl/types/internal/optional.h index 6ed0c669..a96d260a 100644 --- a/absl/types/internal/optional.h +++ b/absl/types/internal/optional.h @@ -25,34 +25,6 @@ #include "absl/meta/type_traits.h" #include "absl/utility/utility.h" -// ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS -// -// Inheriting constructors is supported in GCC 4.8+, Clang 3.3+ and MSVC 2015. -// __cpp_inheriting_constructors is a predefined macro and a recommended way to -// check for this language feature, but GCC doesn't support it until 5.0 and -// Clang doesn't support it until 3.6. -// Also, MSVC 2015 has a bug: it doesn't inherit the constexpr template -// constructor. For example, the following code won't work on MSVC 2015 Update3: -// struct Base { -// int t; -// template <typename T> -// constexpr Base(T t_) : t(t_) {} -// }; -// struct Foo : Base { -// using Base::Base; -// } -// constexpr Foo foo(0); // doesn't work on MSVC 2015 -#if defined(__clang__) -#if __has_feature(cxx_inheriting_constructors) -#define ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS 1 -#endif -#elif (defined(__GNUC__) && \ - (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 8)) || \ - (__cpp_inheriting_constructors >= 200802) || \ - (defined(_MSC_VER) && _MSC_VER >= 1910) -#define ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS 1 -#endif - namespace absl { ABSL_NAMESPACE_BEGIN @@ -145,15 +117,7 @@ template <typename T> class optional_data_base : public optional_data_dtor_base<T> { protected: using base = optional_data_dtor_base<T>; -#ifdef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS using base::base; -#else - optional_data_base() = default; - - template <typename... Args> - constexpr explicit optional_data_base(in_place_t t, Args&&... args) - : base(t, absl::forward<Args>(args)...) {} -#endif template <typename... Args> void construct(Args&&... args) { @@ -188,27 +152,13 @@ class optional_data; template <typename T> class optional_data<T, true> : public optional_data_base<T> { protected: -#ifdef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS using optional_data_base<T>::optional_data_base; -#else - optional_data() = default; - - template <typename... Args> - constexpr explicit optional_data(in_place_t t, Args&&... args) - : optional_data_base<T>(t, absl::forward<Args>(args)...) {} -#endif }; template <typename T> class optional_data<T, false> : public optional_data_base<T> { protected: -#ifdef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS using optional_data_base<T>::optional_data_base; -#else - template <typename... Args> - constexpr explicit optional_data(in_place_t t, Args&&... args) - : optional_data_base<T>(t, absl::forward<Args>(args)...) {} -#endif optional_data() = default; @@ -399,6 +349,4 @@ struct optional_hash_base<T, decltype(std::hash<absl::remove_const_t<T> >()( ABSL_NAMESPACE_END } // namespace absl -#undef ABSL_OPTIONAL_USE_INHERITING_CONSTRUCTORS - #endif // ABSL_TYPES_INTERNAL_OPTIONAL_H_ diff --git a/absl/types/internal/span.h b/absl/types/internal/span.h index 344ad4db..ab89ba3c 100644 --- a/absl/types/internal/span.h +++ b/absl/types/internal/span.h @@ -88,7 +88,7 @@ using EnableIfMutable = template <template <typename> class SpanT, typename T> bool EqualImpl(SpanT<T> a, SpanT<T> b) { static_assert(std::is_const<T>::value, ""); - return absl::equal(a.begin(), a.end(), b.begin(), b.end()); + return std::equal(a.begin(), a.end(), b.begin(), b.end()); } template <template <typename> class SpanT, typename T> @@ -125,7 +125,7 @@ struct IsView< }; // These enablers result in 'int' so they can be used as typenames or defaults -// in template paramters lists. +// in template parameters lists. template <typename T> using EnableIfIsView = std::enable_if_t<IsView<T>::value, int>; diff --git a/absl/types/internal/variant.h b/absl/types/internal/variant.h index c82ded44..fc8829e5 100644 --- a/absl/types/internal/variant.h +++ b/absl/types/internal/variant.h @@ -877,8 +877,8 @@ struct IndexOfConstructedType< template <std::size_t... Is> struct ContainsVariantNPos : absl::negation<std::is_same< // NOLINT - absl::integer_sequence<bool, 0 <= Is...>, - absl::integer_sequence<bool, Is != absl::variant_npos...>>> {}; + std::integer_sequence<bool, 0 <= Is...>, + std::integer_sequence<bool, Is != absl::variant_npos...>>> {}; template <class Op, class... QualifiedVariants> using RawVisitResult = diff --git a/absl/types/optional.h b/absl/types/optional.h index 134b2aff..0a8080dc 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -130,7 +130,7 @@ class optional : private optional_internal::optional_data<T>, // Constructs an `optional` holding an empty value, NOT a default constructed // `T`. - constexpr optional() noexcept {} + constexpr optional() noexcept = default; // Constructs an `optional` initialized with `nullopt` to hold an empty value. constexpr optional(nullopt_t) noexcept {} // NOLINT(runtime/explicit) @@ -357,7 +357,7 @@ class optional : private optional_internal::optional_data<T>, template <typename... Args, typename = typename std::enable_if< std::is_constructible<T, Args&&...>::value>::type> - T& emplace(Args&&... args) { + T& emplace(Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { this->destruct(); this->construct(std::forward<Args>(args)...); return reference(); @@ -377,7 +377,8 @@ class optional : private optional_internal::optional_data<T>, template <typename U, typename... Args, typename = typename std::enable_if<std::is_constructible< T, std::initializer_list<U>&, Args&&...>::value>::type> - T& emplace(std::initializer_list<U> il, Args&&... args) { + T& emplace(std::initializer_list<U> il, + Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { this->destruct(); this->construct(il, std::forward<Args>(args)...); return reference(); @@ -414,11 +415,11 @@ class optional : private optional_internal::optional_data<T>, // `optional` is empty, behavior is undefined. // // If you need myOpt->foo in constexpr, use (*myOpt).foo instead. - const T* operator->() const { + const T* operator->() const ABSL_ATTRIBUTE_LIFETIME_BOUND { ABSL_HARDENING_ASSERT(this->engaged_); return std::addressof(this->data_); } - T* operator->() { + T* operator->() ABSL_ATTRIBUTE_LIFETIME_BOUND { ABSL_HARDENING_ASSERT(this->engaged_); return std::addressof(this->data_); } @@ -427,17 +428,17 @@ class optional : private optional_internal::optional_data<T>, // // Accesses the underlying `T` value of an `optional`. If the `optional` is // empty, behavior is undefined. - constexpr const T& operator*() const& { + constexpr const T& operator*() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { return ABSL_HARDENING_ASSERT(this->engaged_), reference(); } - T& operator*() & { + T& operator*() & ABSL_ATTRIBUTE_LIFETIME_BOUND { ABSL_HARDENING_ASSERT(this->engaged_); return reference(); } - constexpr const T&& operator*() const && { + constexpr const T&& operator*() const&& ABSL_ATTRIBUTE_LIFETIME_BOUND { return ABSL_HARDENING_ASSERT(this->engaged_), absl::move(reference()); } - T&& operator*() && { + T&& operator*() && ABSL_ATTRIBUTE_LIFETIME_BOUND { ABSL_HARDENING_ASSERT(this->engaged_); return std::move(reference()); } @@ -472,23 +473,24 @@ class optional : private optional_internal::optional_data<T>, // and lvalue/rvalue-ness of the `optional` is preserved to the view of // the `T` sub-object. Throws `absl::bad_optional_access` when the `optional` // is empty. - constexpr const T& value() const & { + constexpr const T& value() const& ABSL_ATTRIBUTE_LIFETIME_BOUND { return static_cast<bool>(*this) ? reference() : (optional_internal::throw_bad_optional_access(), reference()); } - T& value() & { + T& value() & ABSL_ATTRIBUTE_LIFETIME_BOUND { return static_cast<bool>(*this) ? reference() : (optional_internal::throw_bad_optional_access(), reference()); } - T&& value() && { // NOLINT(build/c++11) + T&& value() && ABSL_ATTRIBUTE_LIFETIME_BOUND { // NOLINT(build/c++11) return std::move( static_cast<bool>(*this) ? reference() : (optional_internal::throw_bad_optional_access(), reference())); } - constexpr const T&& value() const && { // NOLINT(build/c++11) + constexpr const T&& value() + const&& ABSL_ATTRIBUTE_LIFETIME_BOUND { // NOLINT(build/c++11) return absl::move( static_cast<bool>(*this) ? reference() diff --git a/absl/types/optional_test.cc b/absl/types/optional_test.cc index 21653a90..5da297b0 100644 --- a/absl/types/optional_test.cc +++ b/absl/types/optional_test.cc @@ -23,7 +23,7 @@ #include "gtest/gtest.h" #include "absl/base/config.h" -#include "absl/base/internal/raw_logging.h" +#include "absl/log/log.h" #include "absl/meta/type_traits.h" #include "absl/strings/string_view.h" @@ -97,9 +97,9 @@ struct StructorListener { // 4522: multiple assignment operators specified // We wrote multiple of them to test that the correct overloads are selected. #ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4521) -#pragma warning( disable : 4522) +#pragma warning(push) +#pragma warning(disable : 4521) +#pragma warning(disable : 4522) #endif struct Listenable { static StructorListener* listener; @@ -133,20 +133,11 @@ struct Listenable { ~Listenable() { ++listener->destruct; } }; #ifdef _MSC_VER -#pragma warning( pop ) +#pragma warning(pop) #endif StructorListener* Listenable::listener = nullptr; -// ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST is defined to 1 when the standard -// library implementation doesn't marked initializer_list's default constructor -// constexpr. The C++11 standard doesn't specify constexpr on it, but C++14 -// added it. However, libstdc++ 4.7 marked it constexpr. -#if defined(_LIBCPP_VERSION) && \ - (_LIBCPP_STD_VER <= 11 || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)) -#define ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST 1 -#endif - struct ConstexprType { enum CtorTypes { kCtorDefault, @@ -156,10 +147,8 @@ struct ConstexprType { }; constexpr ConstexprType() : x(kCtorDefault) {} constexpr explicit ConstexprType(int i) : x(kCtorInt) {} -#ifndef ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST constexpr ConstexprType(std::initializer_list<int> il) : x(kCtorInitializerList) {} -#endif constexpr ConstexprType(const char*) // NOLINT(runtime/explicit) : x(kCtorConstChar) {} int x; @@ -352,11 +341,9 @@ TEST(optionalTest, InPlaceConstructor) { constexpr absl::optional<ConstexprType> opt1{absl::in_place_t(), 1}; static_assert(opt1, ""); static_assert((*opt1).x == ConstexprType::kCtorInt, ""); -#ifndef ABSL_HAVE_NO_CONSTEXPR_INITIALIZER_LIST constexpr absl::optional<ConstexprType> opt2{absl::in_place_t(), {1, 2}}; static_assert(opt2, ""); static_assert((*opt2).x == ConstexprType::kCtorInitializerList, ""); -#endif EXPECT_FALSE((std::is_constructible<absl::optional<ConvertsFromInPlaceT>, absl::in_place_t>::value)); @@ -1000,9 +987,8 @@ TEST(optionalTest, PointerStuff) { // 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__) +#define GCC_VERSION \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #if GCC_VERSION < 40901 #define ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG #endif @@ -1010,7 +996,7 @@ TEST(optionalTest, PointerStuff) { // 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 ingores the cv-qualifier when generating a +// The compiler some incorrectly ignores the cv-qualifier when generating a // class object via a constructor call. For example: // // class optional { @@ -1214,7 +1200,6 @@ void optionalTest_Comparisons_EXPECT_GREATER(T x, U y) { EXPECT_TRUE(x >= y); } - template <typename T, typename U, typename V> void TestComparisons() { absl::optional<T> ae, a2{2}, a4{4}; @@ -1307,7 +1292,6 @@ TEST(optionalTest, Comparisons) { EXPECT_TRUE(e1 == e2); } - TEST(optionalTest, SwapRegression) { StructorListener listener; Listenable::listener = &listener; @@ -1558,8 +1542,7 @@ TEST(optionalTest, Hash) { struct MoveMeNoThrow { MoveMeNoThrow() : x(0) {} [[noreturn]] MoveMeNoThrow(const MoveMeNoThrow& other) : x(other.x) { - ABSL_RAW_LOG(FATAL, "Should not be called."); - abort(); + LOG(FATAL) << "Should not be called."; } MoveMeNoThrow(MoveMeNoThrow&& other) noexcept : x(other.x) {} int x; diff --git a/absl/types/span.h b/absl/types/span.h index d7bdbb1f..70ed8eb6 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -296,8 +296,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 ABSL_HARDENING_ASSERT(i < size()), *(data() + i); + return ABSL_HARDENING_ASSERT(i < size()), ptr_[i]; } // Span::at() diff --git a/absl/types/span_test.cc b/absl/types/span_test.cc index 13264aae..29e8681f 100644 --- a/absl/types/span_test.cc +++ b/absl/types/span_test.cc @@ -191,7 +191,7 @@ TEST(IntSpan, SpanOfDerived) { } void TestInitializerList(absl::Span<const int> s, const std::vector<int>& v) { - EXPECT_TRUE(absl::equal(s.begin(), s.end(), v.begin(), v.end())); + EXPECT_TRUE(std::equal(s.begin(), s.end(), v.begin(), v.end())); } TEST(ConstIntSpan, InitializerListConversion) { |