This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/39560 (bogus -Wunused with anonymous union)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 12 Nov 2009 18:20:19 -0500
- Subject: C++ PATCH for c++/39560 (bogus -Wunused with anonymous union)
We don't mark the anonymous union variables as used because we replace
them with a COMPONENT_REF whenever they appear. It seems reasonable to
set DECL_ARTIFICIAL on these VAR_DECLs to avoid the warning, since they
are artificial.
Tested x86_64-pc-linux-gnu, applied to trunk.
commit a6cd09bb1b91f388ef4ea9938c93b314d8855b64
Author: Jason Merrill <jason@redhat.com>
Date: Thu Nov 12 17:55:36 2009 -0500
PR c++/39560
* decl2.c (build_anon_union_vars): Set DECL_ARTIFICIAL.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 510aa8f..7c3f7c0 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1313,6 +1313,7 @@ build_anon_union_vars (tree type, tree object)
decl = build_decl (input_location,
VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
DECL_ANON_UNION_VAR_P (decl) = 1;
+ DECL_ARTIFICIAL (decl) = 1;
base = get_base_address (object);
TREE_PUBLIC (decl) = TREE_PUBLIC (base);
diff --git a/gcc/testsuite/g++.dg/lookup/anon7.C b/gcc/testsuite/g++.dg/lookup/anon7.C
new file mode 100644
index 0000000..79cad0a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/anon7.C
@@ -0,0 +1,26 @@
+// PR c++/39560
+// { dg-options -Wunused }
+
+struct X { };
+
+class Z {
+public:
+ X* cc(int c);
+};
+
+class F {
+public:
+ typedef X* (Z::*MethO)(int);
+ typedef X* (F::*MethF)(int);
+ template<MethO m>
+ X* xwrapper(int i) {
+ union {
+ Z *z;
+ F *f;
+ }; // { dg-bogus "unused" }
+ f = this;
+ return ((z->*m)(i));
+ }
+};
+
+F::MethF meth = &F::xwrapper<&Z::cc>;