Skip to content

Commit

Permalink
[NFC] Fix some TriviallyRelocatable test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Feb 13, 2024
1 parent 34604d5 commit c53e2ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 11 additions & 6 deletions absl/meta/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,17 @@ using swap_internal::StdSwapIsUnconstrained;
// absl::is_trivially_relocatable<T>
//
// Detects whether a type is known to be "trivially relocatable" -- meaning it
// can be relocated without invoking the constructor/destructor, using a form of
// move elision.
//
// This trait is conservative, for backwards compatibility. If it's true then
// the type is definitely trivially relocatable, but if it's false then the type
// may or may not be.
// can be relocated from one place to another as if by memcpy/memmove.
// This implies that its object representation doesn't depend on its address,
// and also its move constructor and destructor don't do anything strange.
//
// This trait is conservative. If it's true then the type is definitely
// trivially relocatable, but there are many types which are "Platonically"
// trivially relocatable but for which the type trait returns false because
// it can't introspect into the special members and see that they're not
// doing anything strange. (For example, std::vector<int> is trivially
// relocatable on every known STL implementation, but
// absl::is_trivially_relocatable<std::vector<int>> remains false.)
//
// Example:
//
Expand Down
11 changes: 6 additions & 5 deletions absl/meta/type_traits_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ TEST(TriviallyRelocatable, PrimitiveTypes) {

// User-defined types can be trivially relocatable as long as they don't have a
// user-provided move constructor or destructor.
TEST(TriviallyRelocatable, UserDefinedTriviallyReconstructible) {
TEST(TriviallyRelocatable, UserDefinedTriviallyRelocatable) {
struct S {
int x;
int y;
Expand Down Expand Up @@ -799,12 +799,13 @@ TEST(TriviallyRelocatable, UserProvidedDestructor) {
!(defined(__clang__) && (defined(_WIN32) || defined(_WIN64))) && \
!defined(__APPLE__)
// A type marked with the "trivial ABI" attribute is trivially relocatable even
// if it has user-provided move/copy constructors and a user-provided
// destructor.
TEST(TrivallyRelocatable, TrivialAbi) {
// if it has user-provided special members.
TEST(TriviallyRelocatable, TrivialAbi) {
struct ABSL_ATTRIBUTE_TRIVIAL_ABI S {
S(S&&) {} // NOLINT(modernize-use-equals-default)
S(const S&) {} // NOLINT(modernize-use-equals-default)
void operator=(S&&) {}
void operator=(const S&) {}
~S() {} // NOLINT(modernize-use-equals-default)
};

Expand All @@ -824,7 +825,7 @@ constexpr int64_t NegateIfConstantEvaluated(int64_t i) {

#endif // ABSL_HAVE_CONSTANT_EVALUATED

TEST(TrivallyRelocatable, is_constant_evaluated) {
TEST(IsConstantEvaluated, is_constant_evaluated) {
#ifdef ABSL_HAVE_CONSTANT_EVALUATED
constexpr int64_t constant = NegateIfConstantEvaluated(42);
EXPECT_EQ(constant, -42);
Expand Down

0 comments on commit c53e2ec

Please sign in to comment.