From: Jason Merrill Date: Wed, 4 Apr 2018 19:10:32 +0000 (-0400) Subject: PR c++/84221 - bogus -Wunused with attribute and template. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3dba92a96d5d11dbf34f5d92cec63739657c5369;p=gcc.git PR c++/84221 - bogus -Wunused with attribute and template. * decl2.c (is_late_template_attribute): Handle unused and used normally on non-TYPE_DECL. From-SVN: r259098 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 261bd06b74f..9b754199e69 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-04-04 Jason Merrill + 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. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 6ae6cef78dd..6078fb668a7 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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 index 00000000000..5558f9361fc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-32.C @@ -0,0 +1,9 @@ +// PR c++/84221 +// { dg-additional-options -Wunused } + +template struct __attribute((unused)) A { }; + +void f (void) +{ + A a; // shouldn't warn +}