Patchwork [google] Avoid warning when unused attribute applied to C++ member variables (issue8580044)

login
register
mail settings
Submitter Teresa Johnson
Date April 9, 2013, 6:01 p.m.
Message ID <20130409180156.F21E0804C2@tjsboxrox.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/235151/
State New
Headers show

Comments

Teresa Johnson - April 9, 2013, 6:01 p.m.
This patch is pending on trunk, but I would like to get this into google
branches now as it is causing spurious warnings.

Google ref b/8496800.

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 google branches?

2013-04-09  Teresa Johnson  <tejohnson@google.com>

	* c-family/c-common.c (handle_unused_attribute):


--
This patch is available for review at http://codereview.appspot.com/8580044
Xinliang David Li - April 9, 2013, 7:32 p.m.
Ok -- there are legitimate use cases for this.

David

On Tue, Apr 9, 2013 at 11:01 AM, Teresa Johnson <tejohnson@google.com> wrote:
> This patch is pending on trunk, but I would like to get this into google
> branches now as it is causing spurious warnings.
>
> Google ref b/8496800.
>
> 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 google branches?
>
> 2013-04-09  Teresa Johnson  <tejohnson@google.com>
>
>         * c-family/c-common.c (handle_unused_attribute):
>
> Index: c-family/c-common.c
> ===================================================================
> --- c-family/c-common.c (revision 197640)
> +++ c-family/c-common.c (working copy)
> @@ -6320,6 +6320,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/8580044

Patch

Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c	(revision 197640)
+++ c-family/c-common.c	(working copy)
@@ -6320,6 +6320,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)