This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR c++/53551 - -Wunused-local-typedefs misses uses


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

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;
+}
-- 
		Dodji


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]