From f5dc6fa252cea10cae0495fdf4357f752bf039e1 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 7 Nov 2009 07:26:56 +0000 Subject: Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407. llvm-svn: 86352 --- clang/lib/Sema/SemaDecl.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'clang/lib/Sema/SemaDecl.cpp') 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() && isa(D) && - !isa(D) && !isa(D) && + if (D->isUsed() || D->hasAttr()) + return false; + + if (const ValueDecl *VD = dyn_cast(D)) { + if (const RecordType *RT = VD->getType()->getAs()) { + if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) { + if (!RD->hasTrivialConstructor()) + return false; + if (!RD->hasTrivialDestructor()) + return false; + } + } + } + + return (isa(D) && !isa(D) && + !isa(D) && D->getDeclContext()->isFunctionOrMethod()); } -- cgit v1.2.3