Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407.

llvm-svn: 86352
This commit is contained in:
Anders Carlsson 2009-11-07 07:26:56 +00:00
parent 2889e0e72c
commit f5dc6fa252
2 changed files with 24 additions and 2 deletions

View File

@ -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());
}

View File

@ -4,3 +4,11 @@ template<typename T> void f() {
T t;
t = 17;
}
struct A { A(); };
struct B { ~B(); };
void f() {
A a;
B b;
}