[Diagnostics] Make behaviour of Clang's -Wdeprecated-copy same as in GCC

Do not warn for  functions that are explicitly marked delete or default, which follows the behavior of the GCC warning.
This commit is contained in:
Dávid Bolvanský 2019-11-23 23:57:17 +01:00
parent bc2b380c0d
commit 9e260c12bc
2 changed files with 9 additions and 2 deletions

View File

@ -12406,7 +12406,8 @@ static void diagnoseDeprecatedCopyOperation(Sema &S, CXXMethodDecl *CopyOp) {
// In Microsoft mode, assignment operations don't affect constructors and
// vice versa.
if (RD->hasUserDeclaredDestructor()) {
if (RD->hasUserDeclaredDestructor() &&
RD->getDestructor()->isUserProvided()) {
UserDeclaredOperation = RD->getDestructor();
} else if (!isa<CXXConstructorDecl>(CopyOp) &&
RD->hasUserDeclaredCopyConstructor() &&
@ -12432,7 +12433,7 @@ static void diagnoseDeprecatedCopyOperation(Sema &S, CXXMethodDecl *CopyOp) {
assert(UserDeclaredOperation);
}
if (UserDeclaredOperation) {
if (UserDeclaredOperation && UserDeclaredOperation->isUserProvided()) {
S.Diag(UserDeclaredOperation->getLocation(),
isa<CXXDestructorDecl>(UserDeclaredOperation)
? diag::warn_deprecated_copy_dtor_operation

View File

@ -101,6 +101,12 @@ namespace DeprecatedCopy {
};
Dtor c1, c2(c1); // expected-note {{implicit copy constructor for 'DeprecatedCopy::Dtor' first required here}}
void g() { c1 = c2; } // expected-note {{implicit copy assignment operator for 'DeprecatedCopy::Dtor' first required here}}
struct DefaultedDtor {
~DefaultedDtor() = default;
};
DefaultedDtor d1, d2(d1);
void h() { d1 = d2; }
}
#endif