diff options
author | 2018-08-09 11:32:15 -0700 | |
---|---|---|
committer | 2018-08-09 14:37:31 -0400 | |
commit | f0f15c2778b0e4959244dd25e63f445a455870f5 (patch) | |
tree | 72b1ce696d73f4fda39ff00c30c049333aa27b57 /absl | |
parent | 29ff6d4860070bf8fcbd39c8805d0c32d56628a3 (diff) |
Export of internal Abseil changes.
--
7fb969986d7d5a1b30233a94ae7ea29e1abf8937 by Greg Falcon <gfalcon@google.com>:
Fix whitespace in str_join.h.
PiperOrigin-RevId: 208082852
--
85428003a8a29fbcd92c0b48708a69460eeb0e8f by Abseil Team <absl-team@google.com>:
Add missing back-ticks to the comments.
PiperOrigin-RevId: 207985417
--
0bbac248d5649ac1d7bc71ff1025a11332fb2026 by Abseil Team <absl-team@google.com>:
Internal change.
PiperOrigin-RevId: 207927484
--
f587324b99570b403b4626fb03fce16f0d950b05 by Abseil Team <absl-team@google.com>:
Update BaseCountedInstance to have comparison operators and allow them to be tracked by InstanceTracker.
PiperOrigin-RevId: 207919218
--
d7f410e4f15328412941f16e25ba3735d5bdfda6 by Derek Mauro <dmauro@google.com>:
Internal import of GitHub PR #153
Removed "warning treated as error" flag from MSVC
PiperOrigin-RevId: 207908806
--
59eefc78f8571ffc51cb636894015ce2580508d7 by Abseil Team <absl-team@google.com>:
Fix namespace references in examples from 'std::' to 'absl::'.
PiperOrigin-RevId: 207895230
--
151df17b6544222e29913b034a1296c0e14374d5 by Abseil Team <absl-team@google.com>:
Internal Change
PiperOrigin-RevId: 207894949
GitOrigin-RevId: 7fb969986d7d5a1b30233a94ae7ea29e1abf8937
Change-Id: I00097afbe9610ddb3f2330a2a86dcffde7bb6675
Diffstat (limited to 'absl')
-rw-r--r-- | absl/base/BUILD.bazel | 5 | ||||
-rw-r--r-- | absl/container/BUILD.bazel | 4 | ||||
-rw-r--r-- | absl/container/internal/test_instance_tracker.cc | 1 | ||||
-rw-r--r-- | absl/container/internal/test_instance_tracker.h | 52 | ||||
-rw-r--r-- | absl/container/internal/test_instance_tracker_test.cc | 22 | ||||
-rw-r--r-- | absl/copts.bzl | 5 | ||||
-rw-r--r-- | absl/memory/BUILD.bazel | 2 | ||||
-rw-r--r-- | absl/strings/BUILD.bazel | 2 | ||||
-rw-r--r-- | absl/strings/str_join.h | 1 | ||||
-rw-r--r-- | absl/strings/string_view.h | 4 | ||||
-rw-r--r-- | absl/types/BUILD.bazel | 11 | ||||
-rw-r--r-- | absl/types/variant.h | 4 |
12 files changed, 103 insertions, 10 deletions
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 06d092eb..b0f4b680 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -19,6 +19,7 @@ load( "ABSL_DEFAULT_COPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", + "ABSL_EXCEPTIONS_FLAG_LINKOPTS", ) package(default_visibility = ["//visibility:public"]) @@ -179,6 +180,7 @@ cc_library( srcs = ["internal/throw_delegate.cc"], hdrs = ["internal/throw_delegate.h"], copts = ABSL_DEFAULT_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, visibility = [ "//absl:__subpackages__", ], @@ -193,6 +195,7 @@ cc_test( name = "throw_delegate_test", srcs = ["throw_delegate_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":throw_delegate", "@com_google_googletest//:gtest_main", @@ -225,6 +228,7 @@ cc_library( srcs = ["internal/exception_safety_testing.cc"], hdrs = ["internal/exception_safety_testing.h"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":base", ":config", @@ -241,6 +245,7 @@ cc_test( name = "exception_safety_testing_test", srcs = ["exception_safety_testing_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":exception_safety_testing", "//absl/memory", diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel index 6d5c958f..7b5f52bc 100644 --- a/absl/container/BUILD.bazel +++ b/absl/container/BUILD.bazel @@ -19,6 +19,7 @@ load( "ABSL_DEFAULT_COPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", + "ABSL_EXCEPTIONS_FLAG_LINKOPTS", ) package(default_visibility = ["//visibility:public"]) @@ -62,6 +63,7 @@ cc_test( name = "fixed_array_test", srcs = ["fixed_array_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":fixed_array", "//absl/base:exception_testing", @@ -86,6 +88,7 @@ cc_test( name = "fixed_array_exception_safety_test", srcs = ["fixed_array_exception_safety_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":fixed_array", "//absl/base:exception_safety_testing", @@ -120,6 +123,7 @@ cc_test( name = "inlined_vector_test", srcs = ["inlined_vector_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":inlined_vector", ":test_instance_tracker", diff --git a/absl/container/internal/test_instance_tracker.cc b/absl/container/internal/test_instance_tracker.cc index fe00aca8..b18e0bb7 100644 --- a/absl/container/internal/test_instance_tracker.cc +++ b/absl/container/internal/test_instance_tracker.cc @@ -21,6 +21,7 @@ int BaseCountedInstance::num_live_instances_ = 0; int BaseCountedInstance::num_moves_ = 0; int BaseCountedInstance::num_copies_ = 0; int BaseCountedInstance::num_swaps_ = 0; +int BaseCountedInstance::num_comparisons_ = 0; } // namespace test_internal } // namespace absl diff --git a/absl/container/internal/test_instance_tracker.h b/absl/container/internal/test_instance_tracker.h index cf8f3a53..ec45f574 100644 --- a/absl/container/internal/test_instance_tracker.h +++ b/absl/container/internal/test_instance_tracker.h @@ -22,8 +22,8 @@ namespace absl { namespace test_internal { // A type that counts number of occurences of the type, the live occurrences of -// the type, as well as the number of copies, moves, and swaps that have -// occurred on the type. This is used as a base class for the copyable, +// the type, as well as the number of copies, moves, swaps, and comparisons that +// have occurred on the type. This is used as a base class for the copyable, // copyable+movable, and movable types below that are used in actual tests. Use // InstanceTracker in tests to track the number of instances. class BaseCountedInstance { @@ -66,6 +66,36 @@ class BaseCountedInstance { return *this; } + bool operator==(const BaseCountedInstance& x) const { + ++num_comparisons_; + return value_ == x.value_; + } + + bool operator!=(const BaseCountedInstance& x) const { + ++num_comparisons_; + return value_ != x.value_; + } + + bool operator<(const BaseCountedInstance& x) const { + ++num_comparisons_; + return value_ < x.value_; + } + + bool operator>(const BaseCountedInstance& x) const { + ++num_comparisons_; + return value_ > x.value_; + } + + bool operator<=(const BaseCountedInstance& x) const { + ++num_comparisons_; + return value_ <= x.value_; + } + + bool operator>=(const BaseCountedInstance& x) const { + ++num_comparisons_; + return value_ >= x.value_; + } + int value() const { if (!is_live_) std::abort(); return value_; @@ -108,6 +138,9 @@ class BaseCountedInstance { // Number of times that BaseCountedInstance objects were swapped. static int num_swaps_; + + // Number of times that BaseCountedInstance objects were compared. + static int num_comparisons_; }; // Helper to track the BaseCountedInstance instance counters. Expects that the @@ -152,13 +185,21 @@ class InstanceTracker { // construction or the last call to ResetCopiesMovesSwaps(). int swaps() const { return BaseCountedInstance::num_swaps_ - start_swaps_; } - // Resets the base values for moves, copies and swaps to the current values, - // so that subsequent Get*() calls for moves, copies and swaps will compare to - // the situation at the point of this call. + // Returns the number of comparisons on BaseCountedInstance objects since + // construction or the last call to ResetCopiesMovesSwaps(). + int comparisons() const { + return BaseCountedInstance::num_comparisons_ - start_comparisons_; + } + + // Resets the base values for moves, copies, comparisons, and swaps to the + // current values, so that subsequent Get*() calls for moves, copies, + // comparisons, and swaps will compare to the situation at the point of this + // call. void ResetCopiesMovesSwaps() { start_moves_ = BaseCountedInstance::num_moves_; start_copies_ = BaseCountedInstance::num_copies_; start_swaps_ = BaseCountedInstance::num_swaps_; + start_comparisons_ = BaseCountedInstance::num_comparisons_; } private: @@ -167,6 +208,7 @@ class InstanceTracker { int start_moves_; int start_copies_; int start_swaps_; + int start_comparisons_; }; // Copyable, not movable. diff --git a/absl/container/internal/test_instance_tracker_test.cc b/absl/container/internal/test_instance_tracker_test.cc index 9efb6771..0ae57636 100644 --- a/absl/container/internal/test_instance_tracker_test.cc +++ b/absl/container/internal/test_instance_tracker_test.cc @@ -157,4 +157,26 @@ TEST(TestInstanceTracker, ExistingInstances) { EXPECT_EQ(1, tracker.moves()); } +TEST(TestInstanceTracker, Comparisons) { + InstanceTracker tracker; + MovableOnlyInstance one(1), two(2); + + EXPECT_EQ(0, tracker.comparisons()); + EXPECT_FALSE(one == two); + EXPECT_EQ(1, tracker.comparisons()); + EXPECT_TRUE(one != two); + EXPECT_EQ(2, tracker.comparisons()); + EXPECT_TRUE(one < two); + EXPECT_EQ(3, tracker.comparisons()); + EXPECT_FALSE(one > two); + EXPECT_EQ(4, tracker.comparisons()); + EXPECT_TRUE(one <= two); + EXPECT_EQ(5, tracker.comparisons()); + EXPECT_FALSE(one >= two); + EXPECT_EQ(6, tracker.comparisons()); + + tracker.ResetCopiesMovesSwaps(); + EXPECT_EQ(0, tracker.comparisons()); +} + } // namespace diff --git a/absl/copts.bzl b/absl/copts.bzl index 259de30c..e4b425b0 100644 --- a/absl/copts.bzl +++ b/absl/copts.bzl @@ -35,7 +35,6 @@ GCC_TEST_FLAGS = [ # Docs on groups of flags is preceded by ###. LLVM_FLAGS = [ - # All warnings are treated as errors by implicit -Werror flag "-Wall", "-Wextra", "-Weverything", @@ -151,3 +150,7 @@ ABSL_EXCEPTIONS_FLAG = select({ "//absl:windows": ["/U_HAS_EXCEPTIONS", "/D_HAS_EXCEPTIONS=1", "/EHsc"], "//conditions:default": ["-fexceptions"], }) + +ABSL_EXCEPTIONS_FLAG_LINKOPTS = select({ + "//conditions:default": [], +}) diff --git a/absl/memory/BUILD.bazel b/absl/memory/BUILD.bazel index 46f47b12..89a312ea 100644 --- a/absl/memory/BUILD.bazel +++ b/absl/memory/BUILD.bazel @@ -19,6 +19,7 @@ load( "ABSL_DEFAULT_COPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", + "ABSL_EXCEPTIONS_FLAG_LINKOPTS", ) package(default_visibility = ["//visibility:public"]) @@ -53,6 +54,7 @@ cc_test( "memory_exception_safety_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":memory", "//absl/base:exception_safety_testing", diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index 3a5f1332..6caf8b97 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -19,6 +19,7 @@ load( "ABSL_DEFAULT_COPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", + "ABSL_EXCEPTIONS_FLAG_LINKOPTS", ) package( @@ -237,6 +238,7 @@ cc_test( size = "small", srcs = ["string_view_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, visibility = ["//visibility:private"], deps = [ ":strings", diff --git a/absl/strings/str_join.h b/absl/strings/str_join.h index bd4d0e1d..b0680e83 100644 --- a/absl/strings/str_join.h +++ b/absl/strings/str_join.h @@ -52,6 +52,7 @@ #include <iterator> #include <string> #include <tuple> +#include <type_traits> #include <utility> #include "absl/base/macros.h" diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h index 1537a3f8..96101463 100644 --- a/absl/strings/string_view.h +++ b/absl/strings/string_view.h @@ -340,7 +340,7 @@ 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'. + // `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"); @@ -351,7 +351,7 @@ class string_view { // string_view::compare() // // Performs a lexicographical comparison between the `string_view` and - // another `absl::string_view), returning -1 if `this` is less than, 0 if + // another `absl::string_view`, returning -1 if `this` is less than, 0 if // `this` is equal to, and 1 if `this` is greater than the passed std::string // view. Note that in the case of data equality, a further comparison is made // on the respective sizes of the two `string_view`s to determine which is diff --git a/absl/types/BUILD.bazel b/absl/types/BUILD.bazel index 096c119e..7841a97d 100644 --- a/absl/types/BUILD.bazel +++ b/absl/types/BUILD.bazel @@ -19,6 +19,7 @@ load( "ABSL_DEFAULT_COPTS", "ABSL_TEST_COPTS", "ABSL_EXCEPTIONS_FLAG", + "ABSL_EXCEPTIONS_FLAG_LINKOPTS", ) package(default_visibility = ["//visibility:public"]) @@ -55,6 +56,7 @@ cc_library( "bad_any_cast.h", ], copts = ABSL_EXCEPTIONS_FLAG + ABSL_DEFAULT_COPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, visibility = ["//visibility:private"], deps = [ "//absl/base", @@ -69,6 +71,7 @@ cc_test( "any_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":any", "//absl/base", @@ -100,6 +103,7 @@ cc_test( name = "any_exception_safety_test", srcs = ["any_exception_safety_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":any", "//absl/base:exception_safety_testing", @@ -124,6 +128,7 @@ cc_test( size = "small", srcs = ["span_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":span", "//absl/base:config", @@ -172,6 +177,7 @@ cc_library( srcs = ["bad_optional_access.cc"], hdrs = ["bad_optional_access.h"], copts = ABSL_DEFAULT_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ "//absl/base", "//absl/base:config", @@ -183,6 +189,7 @@ cc_library( srcs = ["bad_variant_access.cc"], hdrs = ["bad_variant_access.h"], copts = ABSL_EXCEPTIONS_FLAG + ABSL_DEFAULT_COPTS, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ "//absl/base", "//absl/base:config", @@ -196,6 +203,7 @@ cc_test( "optional_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":optional", "//absl/base", @@ -212,6 +220,7 @@ cc_test( "optional_exception_safety_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":optional", "//absl/base:exception_safety_testing", @@ -239,6 +248,7 @@ cc_test( size = "small", srcs = ["variant_test.cc"], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":variant", "//absl/base:config", @@ -271,6 +281,7 @@ cc_test( "variant_exception_safety_test.cc", ], copts = ABSL_TEST_COPTS + ABSL_EXCEPTIONS_FLAG, + linkopts = ABSL_EXCEPTIONS_FLAG_LINKOPTS, deps = [ ":variant", "//absl/base:exception_safety_testing", diff --git a/absl/types/variant.h b/absl/types/variant.h index 17e0634d..2f78722f 100644 --- a/absl/types/variant.h +++ b/absl/types/variant.h @@ -414,9 +414,9 @@ constexpr absl::add_pointer_t<const T> get_if( // }; // // // Declare our variant, and call `absl::visit()` on it. -// std::variant<int, std::string> foo = std::string("foo"); +// absl::variant<int, std::string> foo = std::string("foo"); // GetVariant visitor; -// std::visit(visitor, foo); // Prints `The variant's value is: foo' +// absl::visit(visitor, foo); // Prints `The variant's value is: foo' template <typename Visitor, typename... Variants> variant_internal::VisitResult<Visitor, Variants...> visit(Visitor&& vis, Variants&&... vars) { |