[cfe-commits] r158411 - in /cfe/trunk: lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclCXX.cpp test/SemaCXX/warn-unused-member.cpp

Daniel Jasper djasper at google.com
Wed Jun 13 11:31:09 PDT 2012


Author: djasper
Date: Wed Jun 13 13:31:09 2012
New Revision: 158411

URL: http://llvm.org/viewvc/llvm-project?rev=158411&view=rev
Log:
Allow __attribute__((unused)) for fields and make it silence
-Wunused-private-field.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/warn-unused-member.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=158411&r1=158410&r2=158411&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jun 13 13:31:09 2012
@@ -1610,7 +1610,7 @@
   }
 
   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;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=158411&r1=158410&r2=158411&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jun 13 13:31:09 2012
@@ -1646,6 +1646,7 @@
       // 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);

Modified: cfe/trunk/test/SemaCXX/warn-unused-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-member.cpp?rev=158411&r1=158410&r2=158411&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-member.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-member.cpp Wed Jun 13 13:31:09 2012
@@ -115,6 +115,8 @@
   Trivial user_constructor_;
   NonTrivialConstructor non_trivial_constructor_;
   NonTrivialDestructor non_trivial_destructor_;
+
+  int attr_  __attribute__((unused));
 };
 
 class EverythingUsed {





More information about the cfe-commits mailing list