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

Chandler Carruth chandlerc at google.com
Wed Jun 20 23:26:25 PDT 2012


On Wed, Jun 20, 2012 at 11:12 PM, Daniel Jasper <djasper at google.com> wrote:

> I have looked into both suggestions, but I am not sure what the right
> thing is:
>
> __attribute__((used)): According to the gcc docs, "this attribute,
> attached to a function, means that code must be emitted for the function
> even if it appears that the function is not referenced". It doesn't really
> say anything about silencing warnings and the code emitting part does not
> really apply to fields. I am happy to make this attribute silence the
> warning, but I don't know whether that makes sense.
>
> -Wused-but-marked-unused: We run into trouble if certain field usages are
> only conditionally included (#ifdefs, ...).  In that case, it would be
> impossible to create source code that produces neither
> -Wused-but-marked-unused nor -Wunused-private-field if compiled in
> different modes.
>
> Any thoughts?
>

I really should have thought of this when we chatted. It's quite verbose,
but it works:

struct S {
  int platform_specific_member
#ifdef __x86_64__
    __attribute__((unused))
#endif
    ;
};


We just have to make the attribute itself be conditioned on the same thing
as the use of the member. As long as this attribute never impacts
semantics, this should be fine. Do others thing this is too cumbersome?


>
> Daniel
>
> On Thu, Jun 14, 2012 at 7:11 PM, Jordan Rose <jordan_rose at apple.com>wrote:
>
>>
>> On Jun 13, 2012, at 12:21 PM, Jonathan Sauer wrote:
>>
>> > Hello,
>> >
>> >>> 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)
>> >
>> > There already is a warning for this, -Wused-but-marked-unused, which is
>> emitted
>> > when a function marked unused is being used. I think it should be the
>> same with
>> > fields.
>>
>> I agree. Similarly, __attribute__((used)) ought to silence the warning
>> whether we find an actual use or not.
>>
>> (Sorry I didn't think of this in my pre-commit review.)
>>
>> Jordan
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120620/5475bc7b/attachment.html>


More information about the cfe-commits mailing list