diff options
author | Anders Carlsson <andersca@mac.com> | 2009-11-07 07:26:56 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-11-07 07:26:56 +0000 |
commit | f7613d53619d11f46fb07ddb0ea90c9fb0cad027 (patch) | |
tree | 97aa4472bd2e375944e2a41588548f5c85998419 /lib/Sema/SemaDecl.cpp | |
parent | 99a000e3ca7224cd70a2e87cc2751d78595c97f5 (diff) |
Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index df7be10223..8e1a19cbe5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/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()); } |