forked from OSchip/llvm-project
Don't treat variables with non-trivial ctors or dtors as unused. Fixes PR5407.
llvm-svn: 86352
This commit is contained in:
parent
2889e0e72c
commit
f5dc6fa252
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue