aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@redhat.com>2012-09-28 13:32:41 +0000
committerDodji Seketeli <dodji@gcc.gnu.org>2012-09-28 15:32:41 +0200
commitd10402b413dfbc968d7edf21415c659db1646345 (patch)
tree7928841298b3d0e441ba635912fde0644eea753a
parent3b4441db79de403b90038af98f8641c19ff0953b (diff)
downloadgcc-d10402b413dfbc968d7edf21415c659db1646345.zip
gcc-d10402b413dfbc968d7edf21415c659db1646345.tar.gz
gcc-d10402b413dfbc968d7edf21415c659db1646345.tar.bz2
PR c++/54372 - unused attribute inactive on dependant entities
In the example of this patch, gcc/g++ invoked with -Wunused-local-typedefs warns on dependant entities even when those are decorated with the 'unused' attribute. This is because in cplus_decl_attributes, save_template_attributes makes so that the 'unused' attribute is applied to its appertaining entity only at instantiation time. But then at parsing time maybe_warn_unused_local_typedefs checks for TREE_USED before warning. This patch applies the 'unused' attribute at compilation time. Tested on x86_64-unknown-linux-gnu against trunk. gcc/cp/ * decl2.c (is_late_template_attribute): "unused" attribute is to be applied at compile time. gcc/testsuite/ * c-c++-common/Wunused-local-typedefs-2.c: New test. From-SVN: r191830
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl2.c5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c35
4 files changed, 51 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3ba5de4..6550e16 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2012-09-28 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/54372 - unused attribute inactive on dependant entities
+ * decl2.c (is_late_template_attribute): "unused" attribute is to
+ be applied at compile time.
+
2012-09-25 Dodji Seketeli <dodji@redhat.com>
PR c++/29028 - Missed unused warning on using declaration
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 0df4613..a590d17 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1104,6 +1104,11 @@ 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
+ decls. */
+ if (is_attribute_p ("unused", name))
+ return false;
+
/* If any of the arguments are dependent expressions, we can't evaluate
the attribute until instantiation time. */
for (arg = args; arg; arg = TREE_CHAIN (arg))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 407184d..22ff3f5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-28 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/54372 - unused attribute inactive on dependant entities
+ * c-c++-common/Wunused-local-typedefs-2.c: New test.
+
2012-09-25 Dodji Seketeli <dodji@redhat.com>
PR c++/29028 - Missed unused warning on using declaration
diff --git a/gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c b/gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c
new file mode 100644
index 0000000..77bacd7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wunused-local-typedefs-2.c
@@ -0,0 +1,35 @@
+/* Origin PR c++/54372
+ { dg-options "-Wunused-local-typedefs" }
+ { dg-do compile }
+*/
+
+template <typename T>
+void f2()
+{
+ typedef T t __attribute__((unused));
+}
+
+class S
+{
+ template <typename T>
+ void f4()
+ {
+ typedef T t __attribute__((unused));
+ }
+};
+
+template <typename T>
+class tS
+{
+ void f()
+ {
+ typedef T t2 __attribute__((unused));
+ }
+
+ template <typename U>
+ void f2()
+ {
+ typedef T t1 __attribute__((unused));
+ typedef U t2 __attribute__((unused));
+ }
+};