forked from OSchip/llvm-project
Partially reland "[Diagnostics] Put "deprecated copy" warnings into -Wdeprecated-copy""
But do not enable it under -Wextra until libcxx issue is solved.
This commit is contained in:
parent
957d9a0335
commit
4eacc32672
|
@ -128,6 +128,8 @@ def CXX11CompatDeprecatedWritableStr :
|
||||||
|
|
||||||
def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
|
def DeprecatedAttributes : DiagGroup<"deprecated-attributes">;
|
||||||
def DeprecatedCommaSubscript : DiagGroup<"deprecated-comma-subscript">;
|
def DeprecatedCommaSubscript : DiagGroup<"deprecated-comma-subscript">;
|
||||||
|
def DeprecatedCopy : DiagGroup<"deprecated-copy">;
|
||||||
|
def DeprecatedCopyDtor : DiagGroup<"deprecated-copy-dtor">;
|
||||||
def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
|
def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
|
||||||
def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
|
def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
|
||||||
def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
|
def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
|
||||||
|
@ -147,6 +149,8 @@ def DeprecatedWritableStr : DiagGroup<"deprecated-writable-strings",
|
||||||
// FIXME: Why is DeprecatedImplementations not in this group?
|
// FIXME: Why is DeprecatedImplementations not in this group?
|
||||||
def Deprecated : DiagGroup<"deprecated", [DeprecatedAttributes,
|
def Deprecated : DiagGroup<"deprecated", [DeprecatedAttributes,
|
||||||
DeprecatedCommaSubscript,
|
DeprecatedCommaSubscript,
|
||||||
|
DeprecatedCopy,
|
||||||
|
DeprecatedCopyDtor,
|
||||||
DeprecatedDeclarations,
|
DeprecatedDeclarations,
|
||||||
DeprecatedDynamicExceptionSpec,
|
DeprecatedDynamicExceptionSpec,
|
||||||
DeprecatedIncrementBool,
|
DeprecatedIncrementBool,
|
||||||
|
|
|
@ -551,9 +551,13 @@ def err_access_decl : Error<
|
||||||
"use using declarations instead">;
|
"use using declarations instead">;
|
||||||
def warn_deprecated_copy_operation : Warning<
|
def warn_deprecated_copy_operation : Warning<
|
||||||
"definition of implicit copy %select{constructor|assignment operator}1 "
|
"definition of implicit copy %select{constructor|assignment operator}1 "
|
||||||
"for %0 is deprecated because it has a user-declared "
|
"for %0 is deprecated because it has a user-declared copy "
|
||||||
"%select{copy %select{assignment operator|constructor}1|destructor}2">,
|
"%select{assignment operator|constructor}1">,
|
||||||
InGroup<Deprecated>, DefaultIgnore;
|
InGroup<DeprecatedCopy>, DefaultIgnore;
|
||||||
|
def warn_deprecated_copy_dtor_operation : Warning<
|
||||||
|
"definition of implicit copy %select{constructor|assignment operator}1 "
|
||||||
|
"for %0 is deprecated because it has a user-declared destructor">,
|
||||||
|
InGroup<DeprecatedCopyDtor>, DefaultIgnore;
|
||||||
def warn_cxx17_compat_exception_spec_in_signature : Warning<
|
def warn_cxx17_compat_exception_spec_in_signature : Warning<
|
||||||
"mangled name of %0 will change in C++17 due to non-throwing exception "
|
"mangled name of %0 will change in C++17 due to non-throwing exception "
|
||||||
"specification in function signature">, InGroup<CXX17CompatMangling>;
|
"specification in function signature">, InGroup<CXX17CompatMangling>;
|
||||||
|
|
|
@ -12406,8 +12406,7 @@ static void diagnoseDeprecatedCopyOperation(Sema &S, CXXMethodDecl *CopyOp) {
|
||||||
|
|
||||||
// In Microsoft mode, assignment operations don't affect constructors and
|
// In Microsoft mode, assignment operations don't affect constructors and
|
||||||
// vice versa.
|
// vice versa.
|
||||||
if (RD->hasUserDeclaredDestructor() &&
|
if (RD->hasUserDeclaredDestructor()) {
|
||||||
RD->getDestructor()->isUserProvided()) {
|
|
||||||
UserDeclaredOperation = RD->getDestructor();
|
UserDeclaredOperation = RD->getDestructor();
|
||||||
} else if (!isa<CXXConstructorDecl>(CopyOp) &&
|
} else if (!isa<CXXConstructorDecl>(CopyOp) &&
|
||||||
RD->hasUserDeclaredCopyConstructor() &&
|
RD->hasUserDeclaredCopyConstructor() &&
|
||||||
|
@ -12435,9 +12434,10 @@ static void diagnoseDeprecatedCopyOperation(Sema &S, CXXMethodDecl *CopyOp) {
|
||||||
|
|
||||||
if (UserDeclaredOperation && UserDeclaredOperation->isUserProvided()) {
|
if (UserDeclaredOperation && UserDeclaredOperation->isUserProvided()) {
|
||||||
S.Diag(UserDeclaredOperation->getLocation(),
|
S.Diag(UserDeclaredOperation->getLocation(),
|
||||||
diag::warn_deprecated_copy_operation)
|
isa<CXXDestructorDecl>(UserDeclaredOperation)
|
||||||
<< RD << /*copy assignment*/!isa<CXXConstructorDecl>(CopyOp)
|
? diag::warn_deprecated_copy_dtor_operation
|
||||||
<< /*destructor*/isa<CXXDestructorDecl>(UserDeclaredOperation);
|
: diag::warn_deprecated_copy_operation)
|
||||||
|
<< RD << /*copy assignment*/ !isa<CXXConstructorDecl>(CopyOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy -verify
|
||||||
|
// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated-copy-dtor -DDEPRECATED_COPY_DTOR -verify
|
||||||
|
|
||||||
|
#ifdef DEPRECATED_COPY_DTOR
|
||||||
|
struct A {
|
||||||
|
int *ptr;
|
||||||
|
~A() { delete ptr; } // expected-warning {{definition of implicit copy constructor for 'A' is deprecated because it has a user-declared destructor}}
|
||||||
|
};
|
||||||
|
|
||||||
|
void foo() {
|
||||||
|
A a{};
|
||||||
|
A b = a; // expected-note {{implicit copy constructor for 'A' first required here}}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
struct B {
|
||||||
|
B &operator=(const B &); // expected-warning {{definition of implicit copy constructor for 'B' is deprecated because it has a user-declared copy assignment operator}}
|
||||||
|
};
|
||||||
|
|
||||||
|
void bar() {
|
||||||
|
B b1, b2(b1); // expected-note {{implicit copy constructor for 'B' first required here}}
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in New Issue