Patchwork PR c++/53551 - -Wunused-local-typedefs misses uses

login
register
mail settings
Submitter Dodji Seketeli
Date Sept. 20, 2012, 8:15 p.m.
Message ID <m3wqzolacq.fsf@redhat.com>
Download mbox | patch
Permalink /patch/185481/
State New
Headers show

Comments

Dodji Seketeli - Sept. 20, 2012, 8:15 p.m.
Hello,

We don't record the use of a typedef when it's used through a
typename. So on the example of the patch, g++ complains that the 'type'
typedef is not used.  Fixed thus.

Tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp/

	* decl.c (make_typename_type): Record the use of typedefs.

gcc/testsuite/

	* g++.dg/warn/Wunused-local-typedefs-2.C: New test.
---
 gcc/cp/decl.c                                      |    4 +++-
 .../g++.dg/warn/Wunused-local-typedefs-2.C         |   20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C
Jason Merrill - Sept. 24, 2012, 2:56 p.m.
OK.

Jason

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 6b5b986..09550be 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3326,7 +3326,9 @@  make_typename_type (tree context, tree name, enum tag_types tag_type,
   
   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
     t = TREE_TYPE (t);
-  
+
+  maybe_record_typedef_use (t);
+
   return t;
 }
 
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C b/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C
new file mode 100644
index 0000000..073e253
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wunused-local-typedefs-2.C
@@ -0,0 +1,20 @@ 
+// Origin PR c++/33255
+// { dg-options "-Wunused" } <-- should trigger -Wunused-local-typedefs
+// { dg-do compile { target c++11 } }
+
+template <typename C>
+struct structure
+{
+    typename C::type val;
+};
+
+int
+main()
+{
+  struct context
+  {
+      using type = int;
+  };
+
+  return structure<context>{42}.val;
+}