PR c++/84221 - bogus -Wunused with attribute and template.
authorJason Merrill <jason@redhat.com>
Wed, 4 Apr 2018 19:10:32 +0000 (15:10 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 4 Apr 2018 19:10:32 +0000 (15:10 -0400)
* decl2.c (is_late_template_attribute): Handle unused and used
normally on non-TYPE_DECL.

From-SVN: r259098

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/g++.dg/warn/Wunused-var-32.C [new file with mode: 0644]

index 261bd06b74f42623ef8b4e24884cc55d0c2f0754..9b754199e696beff7283fbd528b071a554cb5620 100644 (file)
@@ -1,5 +1,9 @@
 2018-04-04  Jason Merrill  <jason@redhat.com>
 
+       PR c++/84221 - bogus -Wunused with attribute and template.
+       * decl2.c (is_late_template_attribute): Handle unused and used
+       normally on non-TYPE_DECL.
+
        PR c++/85135 - ICE with omitted template arguments.
        * decl.c (grokdeclarator): Catch deduced class type in trailing
        return type.
index 6ae6cef78dda0de2b536173285d3e8d3fa8ef514..6078fb668a766039b1e8ab8e44cb6ba33aae100f 100644 (file)
@@ -1145,10 +1145,11 @@ is_late_template_attribute (tree attr, tree decl)
   if (is_attribute_p ("weak", name))
     return true;
 
-  /* Attributes used and unused are applied directly, as they appertain to
-     decls. */
-  if (is_attribute_p ("unused", name)
-      || is_attribute_p ("used", name))
+  /* Attributes used and unused are applied directly to typedefs for the
+     benefit of maybe_warn_unused_local_typedefs.  */
+  if (TREE_CODE (decl) == TYPE_DECL
+      && (is_attribute_p ("unused", name)
+         || is_attribute_p ("used", name)))
     return false;
 
   /* Attribute tls_model wants to modify the symtab.  */
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-32.C b/gcc/testsuite/g++.dg/warn/Wunused-var-32.C
new file mode 100644 (file)
index 0000000..5558f93
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/84221
+// { dg-additional-options -Wunused }
+
+template <class T> struct __attribute((unused)) A { };
+
+void f (void)
+{
+  A<int> a;   // shouldn't warn
+}