Skip to content

[Clang] Fix replaceability/relocatability computation #145655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaTypeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static bool hasSuitableConstructorForRelocation(Sema &SemaRef,

CXXMethodDecl *Decl =
LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false);
return Decl && Decl->isUserProvided() == AllowUserDefined &&
return Decl && (AllowUserDefined || !Decl->isUserProvided()) &&
!Decl->isDeleted();
}

Expand All @@ -137,7 +137,7 @@ static bool hasSuitableMoveAssignmentOperatorForRelocation(
if (!Decl)
return false;

return Decl && Decl->isUserProvided() == AllowUserDefined &&
return Decl && (AllowUserDefined || !Decl->isUserProvided()) &&
!Decl->isDeleted();
}

Expand Down
36 changes: 36 additions & 0 deletions clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,39 @@ C& C::operator=(const C&) = default;
static_assert (!__builtin_is_cpp_trivially_relocatable(C));
static_assert (!__builtin_is_replaceable(C));
}

namespace GH144232 {

struct E trivially_relocatable_if_eligible replaceable_if_eligible {
E (E &&);
E &operator= (E &&) = default;
};

struct F trivially_relocatable_if_eligible replaceable_if_eligible {
F (F &&) = default;
F &operator= (F &&);
};

struct G trivially_relocatable_if_eligible replaceable_if_eligible { G (G const &) = default; };

struct I trivially_relocatable_if_eligible replaceable_if_eligible { I &operator= (const I &) = default; };

struct J trivially_relocatable_if_eligible replaceable_if_eligible { J (J const &); };
struct K trivially_relocatable_if_eligible replaceable_if_eligible { K (K const &); };



static_assert (__builtin_is_replaceable (E));
static_assert (__builtin_is_cpp_trivially_relocatable(E));
static_assert (__builtin_is_replaceable (F));
static_assert (__builtin_is_cpp_trivially_relocatable(F));
static_assert (__builtin_is_replaceable (G));
static_assert (__builtin_is_cpp_trivially_relocatable(G));
static_assert (__builtin_is_replaceable (I));
static_assert (__builtin_is_cpp_trivially_relocatable(I));
static_assert (__builtin_is_replaceable (J));
static_assert (__builtin_is_cpp_trivially_relocatable(J));
static_assert (__builtin_is_replaceable (K));
static_assert (__builtin_is_cpp_trivially_relocatable(K));

}
Loading