diff options
author | 2022-09-20 13:12:25 -0700 | |
---|---|---|
committer | 2022-09-20 13:13:13 -0700 | |
commit | d859fafe1ab9edc9c04ca262d9993be82c757881 (patch) | |
tree | 6794fb010d0f423ea6a8fb65176efb9231ad095d /absl/meta/type_traits_test.cc | |
parent | 800c04f64afa48271c6eaee67da489a7ebf92757 (diff) |
Change the macro ABSL_IS_TRIVIALLY_RELOCATABLE into a type trait - absl::is_trivially_relocatable - and move it from optimization.h to type_traits.h.
Example of how to change to the new type trait:
```
#include "absl/base/attributes.h"
if (ABSL_IS_TRIVIALLY_RELOCATABLE(T)) { DoSomething(); }
```
to
```
#include "absl/meta/type_traits.h"
if (absl::is_trivially_relocatable<T>::value) { DoSomething(); }
```
Note that optimization.h is also built in C mode so we can't put a type trait there.
PiperOrigin-RevId: 475633715
Change-Id: I2bc85f3f6711d1280049fd01eb97c497d2d0d929
Diffstat (limited to 'absl/meta/type_traits_test.cc')
-rw-r--r-- | absl/meta/type_traits_test.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index fe96554d..d08d9ad9 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -21,6 +21,7 @@ #include <vector> #include "gtest/gtest.h" +#include "absl/base/attributes.h" namespace { @@ -1394,4 +1395,22 @@ TEST(TypeTraitsTest, IsNothrowSwappable) { EXPECT_TRUE(IsNothrowSwappable<adl_namespace::SpecialNoexceptSwap>::value); } +TEST(TrivallyRelocatable, Sanity) { +#if !defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) || \ + !ABSL_HAVE_BUILTIN(__is_trivially_relocatable) + GTEST_SKIP() << "No trivial ABI support."; +#endif + + struct Trivial {}; + struct NonTrivial { + NonTrivial(const NonTrivial&) {} // NOLINT + }; + struct ABSL_ATTRIBUTE_TRIVIAL_ABI TrivialAbi { + TrivialAbi(const TrivialAbi&) {} // NOLINT + }; + EXPECT_TRUE(absl::is_trivially_relocatable<Trivial>::value); + EXPECT_FALSE(absl::is_trivially_relocatable<NonTrivial>::value); + EXPECT_TRUE(absl::is_trivially_relocatable<TrivialAbi>::value); +} + } // namespace |