summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-11-07 07:26:56 +0000
committerAnders Carlsson <andersca@mac.com>2009-11-07 07:26:56 +0000
commitf5dc6fa252cea10cae0495fdf4357f752bf039e1 (patch)
tree61e3a74e21523a866ff569ba4f4adaa9fd23b103 /clang/lib/Sema/SemaDecl.cpp
parent2889e0e72c73edc07f7992ea95667fb6d56a5a0f (diff)
downloadbcm5719-llvm-f5dc6fa252cea10cae0495fdf4357f752bf039e1.tar.gz
bcm5719-llvm-f5dc6fa252cea10cae0495fdf4357f752bf039e1.zip
Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407.
llvm-svn: 86352
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index df7be102235..8e1a19cbe5c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -385,8 +385,22 @@ bool Sema::isDeclInScope(NamedDecl *&D, DeclContext *Ctx, Scope *S) {
}
static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
- return (!D->isUsed() && !D->hasAttr<UnusedAttr>() && isa<VarDecl>(D) &&
- !isa<ParmVarDecl>(D) && !isa<ImplicitParamDecl>(D) &&
+ if (D->isUsed() || D->hasAttr<UnusedAttr>())
+ return false;
+
+ if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
+ if (const RecordType *RT = VD->getType()->getAs<RecordType>()) {
+ if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+ if (!RD->hasTrivialConstructor())
+ return false;
+ if (!RD->hasTrivialDestructor())
+ return false;
+ }
+ }
+ }
+
+ return (isa<VarDecl>(D) && !isa<ParmVarDecl>(D) &&
+ !isa<ImplicitParamDecl>(D) &&
D->getDeclContext()->isFunctionOrMethod());
}
OpenPOWER on IntegriCloud