Allow __attribute__((unused)) for fields and make it silence

-Wunused-private-field.

llvm-svn: 158411
This commit is contained in:
Daniel Jasper 2012-06-13 18:31:09 +00:00
parent f0273603f5
commit 429c134d5d
3 changed files with 4 additions and 1 deletions

View File

@ -1610,7 +1610,7 @@ static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
}
if (!isa<VarDecl>(D) && !isa<ObjCIvarDecl>(D) && !isFunctionOrMethod(D) &&
!isa<TypeDecl>(D) && !isa<LabelDecl>(D)) {
!isa<TypeDecl>(D) && !isa<LabelDecl>(D) && !isa<FieldDecl>(D)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << ExpectedVariableFunctionOrLabel;
return;

View File

@ -1646,6 +1646,7 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
// effects and are not part of a dependent type declaration.
if (!FD->isImplicit() && FD->getDeclName() &&
FD->getAccess() == AS_private &&
!FD->hasAttr<UnusedAttr>() &&
!FD->getParent()->getTypeForDecl()->isDependentType() &&
!InitializationHasSideEffects(*FD))
UnusedPrivateFields.insert(FD);

View File

@ -115,6 +115,8 @@ class A {
Trivial user_constructor_;
NonTrivialConstructor non_trivial_constructor_;
NonTrivialDestructor non_trivial_destructor_;
int attr_ __attribute__((unused));
};
class EverythingUsed {