Skip to content

[Clang] _default-movable_ should be based on the first declaration #143661

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 3 commits into from
Jun 11, 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
16 changes: 10 additions & 6 deletions clang/lib/Sema/SemaTypeTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static CXXMethodDecl *LookupSpecialMemberFromXValue(Sema &SemaRef,
switch (OCS.BestViableFunction(SemaRef, LookupLoc, Best)) {
case OR_Success:
case OR_Deleted:
return cast<CXXMethodDecl>(Best->Function);
return cast<CXXMethodDecl>(Best->Function)->getCanonicalDecl();
default:
return nullptr;
}
Expand Down Expand Up @@ -164,6 +164,8 @@ static bool IsDefaultMovable(Sema &SemaRef, const CXXRecordDecl *D) {
if (!Dtr)
return true;

Dtr = Dtr->getCanonicalDecl();

if (Dtr->isUserProvided() && (!Dtr->isDefaulted() || Dtr->isDeleted()))
return false;

Expand Down Expand Up @@ -2044,11 +2046,13 @@ static void DiagnoseNonDefaultMovable(Sema &SemaRef, SourceLocation Loc,
<< diag::TraitNotSatisfiedReason::UserProvidedAssign
<< Decl->isMoveAssignmentOperator() << Decl->getSourceRange();
}
CXXDestructorDecl *Dtr = D->getDestructor();
if (Dtr && Dtr->isUserProvided() && !Dtr->isDefaulted())
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
<< diag::TraitNotSatisfiedReason::DeletedDtr << /*User Provided*/ 1
<< Dtr->getSourceRange();
if (CXXDestructorDecl *Dtr = D->getDestructor()) {
Dtr = Dtr->getCanonicalDecl();
if (Dtr->isUserProvided() && !Dtr->isDefaulted())
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
<< diag::TraitNotSatisfiedReason::DeletedDtr << /*User Provided*/ 1
<< Dtr->getSourceRange();
}
}

static void DiagnoseNonTriviallyRelocatableReason(Sema &SemaRef,
Expand Down
21 changes: 21 additions & 0 deletions clang/test/SemaCXX/cxx2c-trivially-relocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,24 @@ void do_test__builtin_trivially_relocate() {
// expected-note@-1 {{'test__builtin_trivially_relocate<S *, S *, int>' requested here}}
// expected-error@#reloc1 {{first argument to '__builtin_trivially_relocate' must be relocatable}}
}


namespace GH143599 {
struct A { ~A (); };
A::~A () = default;

static_assert (!__builtin_is_cpp_trivially_relocatable(A));
static_assert (!__builtin_is_replaceable(A));

struct B { B(const B&); };
B::B (const B&) = default;

static_assert (!__builtin_is_cpp_trivially_relocatable(B));
static_assert (!__builtin_is_replaceable(B));

struct C { C& operator=(const C&); };
C& C::operator=(const C&) = default;

static_assert (!__builtin_is_cpp_trivially_relocatable(C));
static_assert (!__builtin_is_replaceable(C));
}
23 changes: 23 additions & 0 deletions clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,29 @@ static_assert(__builtin_is_cpp_trivially_relocatable(UnionOfPolymorphic));

}

struct GH143599 { // expected-note 2 {{'GH143599' defined here}}
~GH143599 ();
GH143599(const GH143599&);
GH143599& operator=(const GH143599&);
};
GH143599::~GH143599 () = default;
GH143599::GH143599 (const GH143599&) = default;
GH143599& GH143599::operator=(const GH143599&) = default;

static_assert (__builtin_is_cpp_trivially_relocatable(GH143599));
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(GH143599)'}} \
// expected-note@-1 {{'GH143599' is not trivially relocatable}} \
// expected-note@-1 {{because it has a user provided copy constructor}} \
// expected-note@-1 {{because it has a user provided copy assignment operator}} \
// expected-note@-1 {{because it has a user-provided destructor}}

static_assert (__builtin_is_replaceable(GH143599));
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_replaceable(GH143599)'}} \
// expected-note@-1 {{'GH143599' is not replaceable}} \
// expected-note@-1 {{because it has a user provided copy constructor}} \
// expected-note@-1 {{because it has a user provided copy assignment operator}} \
// expected-note@-1 {{because it has a user-provided destructor}}

namespace trivially_copyable {
struct B {
virtual ~B();
Expand Down