- abacaab4b11a69dd4db627bd183571d7cabb8def Refinement to previous time.h edit (in this same github p... by Greg Falcon <gfalcon@google.com>
- 64db19b773134c6c8004e3b23c9ca892efbf8bae Move SpinLock's adaptive spin count computation from a st... by Derek Mauro <dmauro@google.com> - 6f9533fb44a52485a7c2bbb9b4efc7bf8d6c359a Import of CCTZ from GitHub. by Abseil Team <absl-team@google.com> - a211d7255c986e8dd4ceada362c0d054a6a1969a Cleanup exception flags by Abseil Team <absl-team@google.com> - babdb29c590126fe9bba5229fe91034b5b5c358a Release time benchmarks. by Alex Strelnikov <strel@google.com> - 5803b32a3ff123d1fb57a0c471d199c818357c9f Release memutil microbenchmarks. by Alex Strelnikov <strel@google.com> - 5357d4890d30e80c53beb05af32500fb20e9402b Add parens around expansion of ABSL_PREDICT_{FALSE,TRUE} ... by Abseil Team <absl-team@google.com> - 32023f61a239a5f6b1c59e577bfe81b179bbcd2d Reformat build rule tag. by Alex Strelnikov <strel@google.com> - 833758ecf2b0cf7a42bbd50b5b127e416425c168 Release uint128 microbenchmarks. by Alex Strelnikov <strel@google.com> - c115a9bca1f944b90fdc78a56b2de176466b124f Disambiguate bitwise-not of size_type by Abseil Team <absl-team@google.com> - f6905f5b5f6e425792de646edafde440548d9346 Updates ConstructorTracker and TrackedObjects with 1) a m... by Abseil Team <absl-team@google.com> - 147c553bdd5d2db20a38f75c4d1ef973d6c709c5 Changes the absl::Duration factory functions to disallow ... by Greg Miller <jgm@google.com> - dba2b96d11b5264546b283ba452f2de1303b0f07 White space fix by Alex Strelnikov <strel@google.com> GitOrigin-RevId: abacaab4b11a69dd4db627bd183571d7cabb8def Change-Id: I6fa34f20d0b2f898e7b5475a603111413bb80a67
This commit is contained in:
parent
7aacab8ae0
commit
92020a042c
22 changed files with 1808 additions and 282 deletions
|
@ -28,7 +28,7 @@ licenses(["notice"]) # Apache 2.0
|
|||
cc_library(
|
||||
name = "any",
|
||||
hdrs = ["any.h"],
|
||||
copts = ABSL_DEFAULT_COPTS + ABSL_EXCEPTIONS_FLAG,
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
deps = [
|
||||
":bad_any_cast",
|
||||
"//absl/base:config",
|
||||
|
@ -40,9 +40,19 @@ cc_library(
|
|||
|
||||
cc_library(
|
||||
name = "bad_any_cast",
|
||||
srcs = ["bad_any_cast.cc"],
|
||||
hdrs = ["bad_any_cast.h"],
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
deps = [":bad_any_cast_impl"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "bad_any_cast_impl",
|
||||
srcs = [
|
||||
"bad_any_cast.cc",
|
||||
"bad_any_cast.h",
|
||||
],
|
||||
copts = ABSL_EXCEPTIONS_FLAG + ABSL_DEFAULT_COPTS,
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//absl/base",
|
||||
"//absl/base:config",
|
||||
|
@ -206,7 +216,6 @@ cc_test(
|
|||
],
|
||||
)
|
||||
|
||||
|
||||
cc_library(
|
||||
name = "variant",
|
||||
srcs = ["internal/variant.h"],
|
||||
|
|
|
@ -170,25 +170,22 @@ TEST(OptionalExceptionSafety, EverythingThrowsSwap) {
|
|||
|
||||
TEST(OptionalExceptionSafety, NoThrowMoveSwap) {
|
||||
// Tests the nothrow guarantee for optional of T with non-throwing move
|
||||
auto nothrow_test =
|
||||
MakeExceptionSafetyTester().WithInvariants(testing::nothrow_guarantee);
|
||||
auto nothrow_test_empty = nothrow_test.WithInitialValue(MoveOptional());
|
||||
auto nothrow_test_nonempty =
|
||||
nothrow_test.WithInitialValue(MoveOptional(kInitialInteger));
|
||||
|
||||
auto swap_empty = [](MoveOptional* optional_ptr) {
|
||||
{
|
||||
auto empty = MoveOptional();
|
||||
optional_ptr->swap(empty);
|
||||
};
|
||||
EXPECT_TRUE(nothrow_test_nonempty.Test(swap_empty));
|
||||
|
||||
auto swap_nonempty = [](MoveOptional* optional_ptr) {
|
||||
auto nonempty =
|
||||
MoveOptional(absl::in_place, kUpdatedInteger, testing::nothrow_ctor);
|
||||
optional_ptr->swap(nonempty);
|
||||
};
|
||||
EXPECT_TRUE(nothrow_test_empty.Test(swap_nonempty));
|
||||
EXPECT_TRUE(nothrow_test_nonempty.Test(swap_nonempty));
|
||||
auto nonempty = MoveOptional(kInitialInteger);
|
||||
EXPECT_TRUE(testing::TestNothrowOp([&]() { nonempty.swap(empty); }));
|
||||
}
|
||||
{
|
||||
auto nonempty = MoveOptional(kUpdatedInteger);
|
||||
auto empty = MoveOptional();
|
||||
EXPECT_TRUE(testing::TestNothrowOp([&]() { empty.swap(nonempty); }));
|
||||
}
|
||||
{
|
||||
auto nonempty_from = MoveOptional(kUpdatedInteger);
|
||||
auto nonempty_to = MoveOptional(kInitialInteger);
|
||||
EXPECT_TRUE(
|
||||
testing::TestNothrowOp([&]() { nonempty_to.swap(nonempty_from); }));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(OptionalExceptionSafety, CopyAssign) {
|
||||
|
@ -251,32 +248,33 @@ TEST(OptionalExceptionSafety, MoveAssign) {
|
|||
|
||||
TEST(OptionalExceptionSafety, NothrowMoveAssign) {
|
||||
// Tests the nothrow guarantee for optional of T with non-throwing move
|
||||
auto nothrow_test =
|
||||
MakeExceptionSafetyTester().WithInvariants(testing::nothrow_guarantee);
|
||||
auto nothrow_test_empty = nothrow_test.WithInitialValue(MoveOptional());
|
||||
auto nothrow_test_nonempty =
|
||||
nothrow_test.WithInitialValue(MoveOptional(kInitialInteger));
|
||||
|
||||
auto moveassign_empty = [](MoveOptional* optional_ptr) {
|
||||
{
|
||||
auto empty = MoveOptional();
|
||||
*optional_ptr = std::move(empty);
|
||||
};
|
||||
EXPECT_TRUE(nothrow_test_nonempty.Test(moveassign_empty));
|
||||
|
||||
auto moveassign_nonempty = [](MoveOptional* optional_ptr) {
|
||||
auto nonempty =
|
||||
MoveOptional(absl::in_place, kUpdatedInteger, testing::nothrow_ctor);
|
||||
*optional_ptr = std::move(nonempty);
|
||||
};
|
||||
EXPECT_TRUE(nothrow_test_empty.Test(moveassign_nonempty));
|
||||
EXPECT_TRUE(nothrow_test_nonempty.Test(moveassign_nonempty));
|
||||
|
||||
auto moveassign_thrower = [](MoveOptional* optional_ptr) {
|
||||
auto thrower = MoveThrower(kUpdatedInteger, testing::nothrow_ctor);
|
||||
*optional_ptr = std::move(thrower);
|
||||
};
|
||||
EXPECT_TRUE(nothrow_test_empty.Test(moveassign_thrower));
|
||||
EXPECT_TRUE(nothrow_test_nonempty.Test(moveassign_thrower));
|
||||
auto nonempty = MoveOptional(kInitialInteger);
|
||||
EXPECT_TRUE(testing::TestNothrowOp([&]() { nonempty = std::move(empty); }));
|
||||
}
|
||||
{
|
||||
auto nonempty = MoveOptional(kInitialInteger);
|
||||
auto empty = MoveOptional();
|
||||
EXPECT_TRUE(testing::TestNothrowOp([&]() { empty = std::move(nonempty); }));
|
||||
}
|
||||
{
|
||||
auto nonempty_from = MoveOptional(kUpdatedInteger);
|
||||
auto nonempty_to = MoveOptional(kInitialInteger);
|
||||
EXPECT_TRUE(testing::TestNothrowOp(
|
||||
[&]() { nonempty_to = std::move(nonempty_from); }));
|
||||
}
|
||||
{
|
||||
auto thrower = MoveThrower(kUpdatedInteger);
|
||||
auto empty = MoveOptional();
|
||||
EXPECT_TRUE(testing::TestNothrowOp([&]() { empty = std::move(thrower); }));
|
||||
}
|
||||
{
|
||||
auto thrower = MoveThrower(kUpdatedInteger);
|
||||
auto nonempty = MoveOptional(kInitialInteger);
|
||||
EXPECT_TRUE(
|
||||
testing::TestNothrowOp([&]() { nonempty = std::move(thrower); }));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -279,7 +279,7 @@ class Span {
|
|||
using size_type = size_t;
|
||||
using difference_type = ptrdiff_t;
|
||||
|
||||
static const size_type npos = ~size_type{0};
|
||||
static const size_type npos = ~(size_type(0));
|
||||
|
||||
constexpr Span() noexcept : Span(nullptr, 0) {}
|
||||
constexpr Span(pointer array, size_type length) noexcept
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace absl {
|
|||
namespace {
|
||||
|
||||
using ::testing::MakeExceptionSafetyTester;
|
||||
using ::testing::nothrow_guarantee;
|
||||
using ::testing::strong_guarantee;
|
||||
using ::testing::TestNothrowOp;
|
||||
using ::testing::TestThrowingCtor;
|
||||
|
||||
using Thrower = testing::ThrowingValue<>;
|
||||
|
@ -120,7 +120,11 @@ testing::AssertionResult CheckInvariants(ThrowingVariant* v) {
|
|||
return AssertionSuccess();
|
||||
}
|
||||
|
||||
Thrower ExpectedThrower() { return Thrower(42); }
|
||||
template <typename... Args>
|
||||
Thrower ExpectedThrower(Args&&... args) {
|
||||
return Thrower(42, args...);
|
||||
}
|
||||
|
||||
ThrowerVec ExpectedThrowerVec() { return {Thrower(100), Thrower(200)}; }
|
||||
ThrowingVariant ValuelessByException() {
|
||||
ThrowingVariant v;
|
||||
|
@ -193,18 +197,14 @@ TEST(VariantExceptionSafetyTest, CopyAssign) {
|
|||
{
|
||||
// - neither *this nor rhs holds a value
|
||||
const ThrowingVariant rhs = ValuelessByException();
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(ValuelessByException())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([&rhs](ThrowingVariant* lhs) { *lhs = rhs; }));
|
||||
ThrowingVariant lhs = ValuelessByException();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = rhs; }));
|
||||
}
|
||||
{
|
||||
// - *this holds a value but rhs does not
|
||||
const ThrowingVariant rhs = ValuelessByException();
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([&rhs](ThrowingVariant* lhs) { *lhs = rhs; }));
|
||||
ThrowingVariant lhs = WithThrower();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = rhs; }));
|
||||
}
|
||||
// - index() == j
|
||||
{
|
||||
|
@ -237,10 +237,8 @@ TEST(VariantExceptionSafetyTest, CopyAssign) {
|
|||
// should not throw because emplace() invokes Tj's copy ctor
|
||||
// which should not throw.
|
||||
const ThrowingVariant rhs(CopyNothrow{});
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([&rhs](ThrowingVariant* lhs) { *lhs = rhs; }));
|
||||
ThrowingVariant lhs = WithThrower();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = rhs; }));
|
||||
}
|
||||
{
|
||||
// is_nothrow_copy_constructible<Tj> == false &&
|
||||
|
@ -281,23 +279,14 @@ TEST(VariantExceptionSafetyTest, MoveAssign) {
|
|||
{
|
||||
// - neither *this nor rhs holds a value
|
||||
ThrowingVariant rhs = ValuelessByException();
|
||||
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(ValuelessByException())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
}));
|
||||
ThrowingVariant lhs = ValuelessByException();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = std::move(rhs); }));
|
||||
}
|
||||
{
|
||||
// - *this holds a value but rhs does not
|
||||
ThrowingVariant rhs = ValuelessByException();
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
}));
|
||||
ThrowingVariant lhs = WithThrower();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = std::move(rhs); }));
|
||||
}
|
||||
{
|
||||
// - index() == j
|
||||
|
@ -310,13 +299,14 @@ TEST(VariantExceptionSafetyTest, MoveAssign) {
|
|||
// Since Thrower's move assignment has basic guarantee, so should variant's.
|
||||
auto tester = MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithOperation([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
.WithOperation([&](ThrowingVariant* lhs) {
|
||||
auto copy = rhs;
|
||||
*lhs = std::move(copy);
|
||||
});
|
||||
EXPECT_TRUE(tester
|
||||
.WithInvariants(
|
||||
CheckInvariants,
|
||||
[j](ThrowingVariant* lhs) { return lhs->index() == j; })
|
||||
[&](ThrowingVariant* lhs) { return lhs->index() == j; })
|
||||
.Test());
|
||||
EXPECT_FALSE(tester.WithInvariants(strong_guarantee).Test());
|
||||
}
|
||||
|
@ -332,8 +322,9 @@ TEST(VariantExceptionSafetyTest, MoveAssign) {
|
|||
[](ThrowingVariant* lhs) {
|
||||
return lhs->valueless_by_exception();
|
||||
})
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
.Test([&](ThrowingVariant* lhs) {
|
||||
auto copy = rhs;
|
||||
*lhs = std::move(copy);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -365,8 +356,9 @@ TEST(VariantExceptionSafetyTest, ValueAssign) {
|
|||
// move assign
|
||||
auto move_tester = MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithOperation([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
.WithOperation([&](ThrowingVariant* lhs) {
|
||||
auto copy = rhs;
|
||||
*lhs = std::move(copy);
|
||||
});
|
||||
EXPECT_TRUE(move_tester
|
||||
.WithInvariants(CheckInvariants,
|
||||
|
@ -388,19 +380,13 @@ TEST(VariantExceptionSafetyTest, ValueAssign) {
|
|||
// invokes the copy/move constructor and it should not throw.
|
||||
{
|
||||
const CopyNothrow rhs;
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([&rhs](ThrowingVariant* lhs) { *lhs = rhs; }));
|
||||
ThrowingVariant lhs = WithThrower();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = rhs; }));
|
||||
}
|
||||
{
|
||||
MoveNothrow rhs;
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
}));
|
||||
ThrowingVariant lhs = WithThrower();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs = std::move(rhs); }));
|
||||
}
|
||||
// if is_nothrow_constructible_v<Tj, T> == false &&
|
||||
// is_nothrow_move_constructible<Tj> == false
|
||||
|
@ -423,8 +409,8 @@ TEST(VariantExceptionSafetyTest, ValueAssign) {
|
|||
// move
|
||||
auto move_tester = MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithCopyNoThrow())
|
||||
.WithOperation([rhs](ThrowingVariant* lhs) mutable {
|
||||
*lhs = std::move(rhs);
|
||||
.WithOperation([](ThrowingVariant* lhs) {
|
||||
*lhs = ExpectedThrower(testing::nothrow_ctor);
|
||||
});
|
||||
EXPECT_TRUE(move_tester
|
||||
.WithInvariants(CheckInvariants,
|
||||
|
@ -477,21 +463,20 @@ TEST(VariantExceptionSafetyTest, Swap) {
|
|||
// if both are valueless_by_exception(), no effect
|
||||
{
|
||||
ThrowingVariant rhs = ValuelessByException();
|
||||
EXPECT_TRUE(
|
||||
MakeExceptionSafetyTester()
|
||||
.WithInitialValue(ValuelessByException())
|
||||
.WithInvariants(nothrow_guarantee)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable { lhs->swap(rhs); }));
|
||||
ThrowingVariant lhs = ValuelessByException();
|
||||
EXPECT_TRUE(TestNothrowOp([&]() { lhs.swap(rhs); }));
|
||||
}
|
||||
// if index() == rhs.index(), calls swap(get<i>(*this), get<i>(rhs))
|
||||
// where i is index().
|
||||
{
|
||||
ThrowingVariant rhs = ExpectedThrower();
|
||||
EXPECT_TRUE(
|
||||
MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(CheckInvariants)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable { lhs->swap(rhs); }));
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithThrower())
|
||||
.WithInvariants(CheckInvariants)
|
||||
.Test([&](ThrowingVariant* lhs) {
|
||||
auto copy = rhs;
|
||||
lhs->swap(copy);
|
||||
}));
|
||||
}
|
||||
// Otherwise, exchanges the value of rhs and *this. The exception safety
|
||||
// involves variant in moved-from state which is not specified in the
|
||||
|
@ -499,19 +484,23 @@ TEST(VariantExceptionSafetyTest, Swap) {
|
|||
// overall strong guarantee. So, we are only checking basic guarantee here.
|
||||
{
|
||||
ThrowingVariant rhs = ExpectedThrower();
|
||||
EXPECT_TRUE(
|
||||
MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithCopyNoThrow())
|
||||
.WithInvariants(CheckInvariants)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable { lhs->swap(rhs); }));
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithCopyNoThrow())
|
||||
.WithInvariants(CheckInvariants)
|
||||
.Test([&](ThrowingVariant* lhs) {
|
||||
auto copy = rhs;
|
||||
lhs->swap(copy);
|
||||
}));
|
||||
}
|
||||
{
|
||||
ThrowingVariant rhs = ExpectedThrower();
|
||||
EXPECT_TRUE(
|
||||
MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithCopyNoThrow())
|
||||
.WithInvariants(CheckInvariants)
|
||||
.Test([rhs](ThrowingVariant* lhs) mutable { rhs.swap(*lhs); }));
|
||||
EXPECT_TRUE(MakeExceptionSafetyTester()
|
||||
.WithInitialValue(WithCopyNoThrow())
|
||||
.WithInvariants(CheckInvariants)
|
||||
.Test([&](ThrowingVariant* lhs) {
|
||||
auto copy = rhs;
|
||||
copy.swap(*lhs);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue