Prevent use of base::NoDestructor for trivially-destructible types
base::NoDestructor prevents calling a destructor of the templated
type. It's not needed if there is no destructor call to prevent.
This relands b961c7632f268f853a88869ad6bc5f33c3a4d549 with a small
fix to code that was behind an official build flag that failed to
compile.
Bug: 1223520
Change-Id: I1dd8ffb3a87436c4047461240a6965447b581d84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2998672
Reviewed-by: danakj <[email protected]>
Reviewed-by: Kevin Marshall <[email protected]>
Owners-Override: danakj <[email protected]>
Commit-Queue: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#898258}
diff --git a/base/no_destructor_unittest.cc b/base/no_destructor_unittest.cc
index 5c83366..ebe19be2 100644
--- a/base/no_destructor_unittest.cc
+++ b/base/no_destructor_unittest.cc
@@ -39,6 +39,7 @@
UncopyableUnmovable& operator=(const UncopyableUnmovable&) = delete;
int value = 1;
+ std::string something_with_a_nontrivial_destructor;
};
struct CopyOnly {
@@ -63,6 +64,8 @@
struct ForwardingTestStruct {
ForwardingTestStruct(const CopyOnly&, MoveOnly&&) {}
+
+ std::string something_with_a_nontrivial_destructor;
};
TEST(NoDestructorTest, UncopyableUnmovable) {
@@ -89,6 +92,11 @@
EXPECT_EQ(0, awesome.get()->compare("awesome"));
}
+TEST(NoDestructorTest, AllowForTriviallyDestructibleType) {
+ static NoDestructor<bool, AllowForTriviallyDestructibleType>
+ trivially_destructible_type;
+}
+
// Passing initializer list to a NoDestructor like in this test
// is ambiguous in GCC.
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84849