diff mbox

C++ PATCH for c++/60063, -Wunused-local-typedefs and attribute used

Message ID CADzB+2mrwtApTzWt-A3OrTGQ3=reN3jMkV_Npufs-O3XQ5LYFQ@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill June 18, 2017, 4:21 a.m. UTC
Attribute used isn't documented to apply to typedefs, but the
implementation allows it.  We should handle it the same way in a
template, by applying it immediately rather than defer until
instantiation time.

Tested x86_64-pc-linux-gnu, applying to trunk and 7.
commit 3c3deed6644421ec32a509df3ffdfc0010b31668
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jun 16 23:30:35 2017 -0400

            PR c++/60063 - -Wunused-local-typedefs and templates.
    
            * decl2.c (is_late_template_attribute): Return false for "used".
diff mbox

Patch

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 69cb40f..72239ec 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1091,9 +1091,10 @@  is_late_template_attribute (tree attr, tree decl)
   if (is_attribute_p ("weak", name))
     return true;
 
-  /* Attribute unused is applied directly, as it appertains to
+  /* Attributes used and unused are applied directly, as they appertain to
      decls. */
-  if (is_attribute_p ("unused", name))
+  if (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-local-typedefs-4.C b/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-4.C
new file mode 100644
index 0000000..7efe112
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-4.C
@@ -0,0 +1,13 @@ 
+// PR c++/60063
+// { dg-options -Wunused-local-typedefs }
+
+template <class> struct S;
+
+void foo (int i) {
+    typedef __attribute__ ((used)) S<int> X;
+}
+
+template <class T>
+void bar (T i) {
+    typedef __attribute__ ((used)) S<T> Y;
+}