diff mbox

Avoid warning when unused attribute applied to C++ member variables (issue8212043)

Message ID 20130331071036.A877C807B2@tjsboxrox.mtv.corp.google.com
State New
Headers show

Commit Message

Teresa Johnson March 31, 2013, 7:10 a.m. UTC
This patch allows the unused attribute to be used without warning
on C++ class members, which are of type FIELD_DECL. This is for
compatibility with clang, which allows the attribute to be specified on
class members and struct fields. It looks like more work would need to
be done to implement the actual unused variable detection and warning
on FIELD_DECLs, but this change will at least avoid the warning on the 
code that uses the unused attribute in these cases. The documentation at 
http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html also doesn't
seem to preclude its use on C++ member variables.

Bootstrapped and tested on x86-64-unknown-linux-gnu. Ok for trunk?

2013-03-30  Teresa Johnson  <tejohnson@google.com>

	* c-family/c-common.c (handle_unused_attribute): Handle
        FIELD_DECL for C++ class members.


--
This patch is available for review at http://codereview.appspot.com/8212043

Comments

Andrew Pinski March 31, 2013, 8:36 a.m. UTC | #1
On Sun, Mar 31, 2013 at 12:10 AM, Teresa Johnson <tejohnson@google.com> wrote:
> This patch allows the unused attribute to be used without warning
> on C++ class members, which are of type FIELD_DECL. This is for
> compatibility with clang, which allows the attribute to be specified on
> class members and struct fields. It looks like more work would need to
> be done to implement the actual unused variable detection and warning
> on FIELD_DECLs, but this change will at least avoid the warning on the
> code that uses the unused attribute in these cases. The documentation at
> http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html also doesn't
> seem to preclude its use on C++ member variables.

This also allows it on field in normal C case.  As far as I understand
they are fields and not variables in the normal programming sense
which is why the document does not mention them.

Thanks,
Andrew Pinski


>
> Bootstrapped and tested on x86-64-unknown-linux-gnu. Ok for trunk?
>
> 2013-03-30  Teresa Johnson  <tejohnson@google.com>
>
>         * c-family/c-common.c (handle_unused_attribute): Handle
>         FIELD_DECL for C++ class members.
>
> Index: c-family/c-common.c
> ===================================================================
> --- c-family/c-common.c (revision 197266)
> +++ c-family/c-common.c (working copy)
> @@ -6753,6 +6753,7 @@ handle_unused_attribute (tree *node, tree name, tr
>
>        if (TREE_CODE (decl) == PARM_DECL
>           || TREE_CODE (decl) == VAR_DECL
> +         || TREE_CODE (decl) == FIELD_DECL
>           || TREE_CODE (decl) == FUNCTION_DECL
>           || TREE_CODE (decl) == LABEL_DECL
>           || TREE_CODE (decl) == TYPE_DECL)
>
> --
> This patch is available for review at http://codereview.appspot.com/8212043
Teresa Johnson March 31, 2013, 4:39 p.m. UTC | #2
On Sun, Mar 31, 2013 at 1:36 AM, Andrew Pinski <pinskia@gmail.com> wrote:
> On Sun, Mar 31, 2013 at 12:10 AM, Teresa Johnson <tejohnson@google.com> wrote:
>> This patch allows the unused attribute to be used without warning
>> on C++ class members, which are of type FIELD_DECL. This is for
>> compatibility with clang, which allows the attribute to be specified on
>> class members and struct fields. It looks like more work would need to
>> be done to implement the actual unused variable detection and warning
>> on FIELD_DECLs, but this change will at least avoid the warning on the
>> code that uses the unused attribute in these cases. The documentation at
>> http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html also doesn't
>> seem to preclude its use on C++ member variables.
>
> This also allows it on field in normal C case.  As far as I understand
> they are fields and not variables in the normal programming sense
> which is why the document does not mention them.

That's true that this change will also allow the unused attribute on
normal C struct fields. I just verified that clang also allows this,
and it could potentially be taken advantage of to warn on unused
fields as well.

Teresa

>
> Thanks,
> Andrew Pinski
>
>
>>
>> Bootstrapped and tested on x86-64-unknown-linux-gnu. Ok for trunk?
>>
>> 2013-03-30  Teresa Johnson  <tejohnson@google.com>
>>
>>         * c-family/c-common.c (handle_unused_attribute): Handle
>>         FIELD_DECL for C++ class members.
>>
>> Index: c-family/c-common.c
>> ===================================================================
>> --- c-family/c-common.c (revision 197266)
>> +++ c-family/c-common.c (working copy)
>> @@ -6753,6 +6753,7 @@ handle_unused_attribute (tree *node, tree name, tr
>>
>>        if (TREE_CODE (decl) == PARM_DECL
>>           || TREE_CODE (decl) == VAR_DECL
>> +         || TREE_CODE (decl) == FIELD_DECL
>>           || TREE_CODE (decl) == FUNCTION_DECL
>>           || TREE_CODE (decl) == LABEL_DECL
>>           || TREE_CODE (decl) == TYPE_DECL)
>>
>> --
>> This patch is available for review at http://codereview.appspot.com/8212043



--
Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413
Teresa Johnson April 8, 2013, 5:18 p.m. UTC | #3
Ping.
Thanks, Teresa

On Sun, Mar 31, 2013 at 9:39 AM, Teresa Johnson <tejohnson@google.com> wrote:
> On Sun, Mar 31, 2013 at 1:36 AM, Andrew Pinski <pinskia@gmail.com> wrote:
>> On Sun, Mar 31, 2013 at 12:10 AM, Teresa Johnson <tejohnson@google.com> wrote:
>>> This patch allows the unused attribute to be used without warning
>>> on C++ class members, which are of type FIELD_DECL. This is for
>>> compatibility with clang, which allows the attribute to be specified on
>>> class members and struct fields. It looks like more work would need to
>>> be done to implement the actual unused variable detection and warning
>>> on FIELD_DECLs, but this change will at least avoid the warning on the
>>> code that uses the unused attribute in these cases. The documentation at
>>> http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html also doesn't
>>> seem to preclude its use on C++ member variables.
>>
>> This also allows it on field in normal C case.  As far as I understand
>> they are fields and not variables in the normal programming sense
>> which is why the document does not mention them.
>
> That's true that this change will also allow the unused attribute on
> normal C struct fields. I just verified that clang also allows this,
> and it could potentially be taken advantage of to warn on unused
> fields as well.
>
> Teresa
>
>>
>> Thanks,
>> Andrew Pinski
>>
>>
>>>
>>> Bootstrapped and tested on x86-64-unknown-linux-gnu. Ok for trunk?
>>>
>>> 2013-03-30  Teresa Johnson  <tejohnson@google.com>
>>>
>>>         * c-family/c-common.c (handle_unused_attribute): Handle
>>>         FIELD_DECL for C++ class members.
>>>
>>> Index: c-family/c-common.c
>>> ===================================================================
>>> --- c-family/c-common.c (revision 197266)
>>> +++ c-family/c-common.c (working copy)
>>> @@ -6753,6 +6753,7 @@ handle_unused_attribute (tree *node, tree name, tr
>>>
>>>        if (TREE_CODE (decl) == PARM_DECL
>>>           || TREE_CODE (decl) == VAR_DECL
>>> +         || TREE_CODE (decl) == FIELD_DECL
>>>           || TREE_CODE (decl) == FUNCTION_DECL
>>>           || TREE_CODE (decl) == LABEL_DECL
>>>           || TREE_CODE (decl) == TYPE_DECL)
>>>
>>> --
>>> This patch is available for review at http://codereview.appspot.com/8212043
>
>
>
> --
> Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413



--
Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413
diff mbox

Patch

Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c	(revision 197266)
+++ c-family/c-common.c	(working copy)
@@ -6753,6 +6753,7 @@  handle_unused_attribute (tree *node, tree name, tr
 
       if (TREE_CODE (decl) == PARM_DECL
 	  || TREE_CODE (decl) == VAR_DECL
+	  || TREE_CODE (decl) == FIELD_DECL
 	  || TREE_CODE (decl) == FUNCTION_DECL
 	  || TREE_CODE (decl) == LABEL_DECL
 	  || TREE_CODE (decl) == TYPE_DECL)