This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/53551 - -Wunused-local-typedefs misses uses
- From: Dodji Seketeli <dodji at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Thu, 20 Sep 2012 22:15:17 +0200
- Subject: [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