diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-15 10:17:33 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-08-15 10:17:33 +0000 |
commit | 06999f8ff61de3c63a52871bd7ac61e7ada9180b (patch) | |
tree | 46ca8505a05bba600ae63a0ea6bef8aca2a36ee9 /lib/Sema/SemaDecl.cpp | |
parent | 57663fe6c3c7a0fb792626537c4f3f7d3594aa66 (diff) |
Don't warn for the common pattern of disallowing copying:
class S {
S(const S&); // DO NOT IMPLEMENT
void operator=(const S&); // DO NOT IMPLEMENT
};
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111100 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ea65c8cf30..3271997e0e 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -521,6 +521,24 @@ static void RemoveUsingDecls(LookupResult &R) { F.done(); } +/// \brief Check for this common pattern: +/// @code +/// class S { +/// S(const S&); // DO NOT IMPLEMENT +/// void operator=(const S&); // DO NOT IMPLEMENT +/// }; +/// @endcode +static bool IsDisallowedCopyOrAssign(const CXXMethodDecl *D) { + // FIXME: Should check for private access too but access is set after we get + // the decl here. + if (D->isThisDeclarationADefinition()) + return false; + + if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D)) + return CD->isCopyConstructor(); + return D->isCopyAssignment(); +} + bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { assert(D); @@ -536,23 +554,23 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const { return false; if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { - if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) - return false; + if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) + return false; - if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { - if (MD->isVirtual()) - return false; - } else { - // 'static inline' functions are used in headers; don't warn. - if (FD->getStorageClass() == FunctionDecl::Static && - FD->isInlineSpecified()) - return false; - } + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { + if (MD->isVirtual() || IsDisallowedCopyOrAssign(MD)) + return false; + } else { + // 'static inline' functions are used in headers; don't warn. + if (FD->getStorageClass() == FunctionDecl::Static && + FD->isInlineSpecified()) + return false; + } if (FD->isThisDeclarationADefinition()) return !Context.DeclMustBeEmitted(FD); return true; - } + } if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { if (VD->isStaticDataMember() && |