From 9e260c12bce77c80aa4da64ac44874687c684580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bolvansk=C3=BD?= Date: Sat, 23 Nov 2019 23:57:17 +0100 Subject: [PATCH] [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. --- clang/lib/Sema/SemaDeclCXX.cpp | 5 +++-- clang/test/SemaCXX/deprecated.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index d7200185bdfc..9c220efebe60 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -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(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(UserDeclaredOperation) ? diag::warn_deprecated_copy_dtor_operation diff --git a/clang/test/SemaCXX/deprecated.cpp b/clang/test/SemaCXX/deprecated.cpp index 878c602d83da..b303c2b4225c 100644 --- a/clang/test/SemaCXX/deprecated.cpp +++ b/clang/test/SemaCXX/deprecated.cpp @@ -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