From 3dba92a96d5d11dbf34f5d92cec63739657c5369 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 4 Apr 2018 15:10:32 -0400 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/decl2.c | 9 +++++---- gcc/testsuite/g++.dg/warn/Wunused-var-32.C | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-32.C 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 +} -- 2.30.2