summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-08-15 10:17:33 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-08-15 10:17:33 +0000
commit04c7fa09e4a219241d3af4c8d6d4b4102e40bb14 (patch)
treec92351716472e7bd80e96ad2339e59a501c85ca9 /clang/lib/Sema/SemaDecl.cpp
parent0ba9fd6c47bc1a49ec9db249d9c30d9cba85564f (diff)
downloadbcm5719-llvm-04c7fa09e4a219241d3af4c8d6d4b4102e40bb14.tar.gz
bcm5719-llvm-04c7fa09e4a219241d3af4c8d6d4b4102e40bb14.zip
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 }; llvm-svn: 111100
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ea65c8cf302..3271997e0e7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/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() &&
OpenPOWER on IntegriCloud