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

David Blaikie dblaikie at gmail.com
Wed Jun 13 11:43:38 PDT 2012


On Wed, Jun 13, 2012 at 11:31 AM, Daniel Jasper <djasper at google.com> wrote:
> 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.

So that these annotations don't get out of date, should we warn when a
field is marked unused but is, in fact, used? (so that when it becomes
used the attribute is cleaned up and doesn't lead to the function
being accidentally unused again in the future)

- David

>
> 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 {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list