This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/42069
- From: Dodji Seketeli <dodji at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: jason at redhat dot com
- Date: Mon, 30 Nov 2009 00:39:48 +0100
- Subject: [PATCH] PR c++/42069
Hello,
In the example accompanying the patch below, we don't strip typedefs for
SCOPE_REFs nodes that are used as template arguments.
This causes a problem very similar to
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39754 .
The resolution of that PR did deal with stripping typedefs from /types/
used as template arguments. I didn't think about stripping typedefs from
SCOPE_REFs then.
The patch below plugs that hole.
Tested against trunk on x86_64-unknown-linux-gnu.
Dodji
commit 4d40b664ded898c391369bf1401d6c4c4ff475db
Author: Dodji Seketeli <dodji@redhat.com>
Date: Sun Nov 29 23:56:33 2009 +0100
Fix PR c++/42069
gcc/cp/ChangeLog:
PR c++/42069
* pt.c (convert_template_argument): Strip typedefs from SCOPE_REFs.
gcc/testsuite/ChanageLog:
PR c++/42069
* g++.dg/template/typedef23.C: New test.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index eb1cdd3..62e931c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5526,6 +5526,13 @@ convert_template_argument (tree parm,
if (TYPE_P (val))
val = strip_typedefs (val);
}
+ else if (TREE_CODE (orig_arg) == SCOPE_REF)
+ {
+ /* Strip typedefs from the SCOPE_REF. */
+ tree type = strip_typedefs (TREE_TYPE (orig_arg));
+ tree scope = strip_typedefs (TREE_OPERAND (orig_arg, 0));
+ val = build2 (SCOPE_REF, type, scope, TREE_OPERAND (orig_arg, 1));
+ }
else
{
tree t = tsubst (TREE_TYPE (parm), args, complain, in_decl);
diff --git a/gcc/testsuite/g++.dg/template/typedef23.C b/gcc/testsuite/g++.dg/template/typedef23.C
new file mode 100644
index 0000000..e703550
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/typedef23.C
@@ -0,0 +1,25 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/42069
+// { dg-do compile }
+
+struct A
+{
+ static const int N = 0;
+};
+
+template<int> struct B {};
+
+template<typename T, int>
+struct C
+{
+ typedef T U;
+ B<U::N> b;
+};
+
+template<typename T>
+struct C<T*, 0>
+{
+ B<T::N> b;
+};
+
+C<A*, 0> c;