re PR c++/47904 (ICE with DECL_PARM_INDEX (this) in cp_tree_equal)
authorJason Merrill <jason@redhat.com>
Sun, 27 Feb 2011 08:13:28 +0000 (03:13 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 27 Feb 2011 08:13:28 +0000 (03:13 -0500)
PR c++/47904
* tree.c (cp_tree_equal): Compare DECL_PARM_LEVEL.
* pt.c (iterative_hash_template_arg): And hash it.

From-SVN: r170533

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/this-targ1.C [new file with mode: 0644]

index 828336212b3d266c7128e2aee4661e7e5f55ee46..50e4b48d5ea36262a9af8840014651ebbf3c8c5c 100644 (file)
@@ -1,5 +1,9 @@
 2011-02-26  Jason Merrill  <jason@redhat.com>
 
+       PR c++/47904
+       * tree.c (cp_tree_equal): Compare DECL_PARM_LEVEL.
+       * pt.c (iterative_hash_template_arg): And hash it.
+
        PR c++/47897
        * semantics.c (non_const_var_error): Split out from...
        (cxx_eval_constant_expression): ...here.
index ed9d28b0b2fd75babc5b6a5d10d80d16ad16034f..4b262d00016d78c54a472cac32567b20a37d0295 100644 (file)
@@ -1533,7 +1533,10 @@ iterative_hash_template_arg (tree arg, hashval_t val)
 
     case PARM_DECL:
       if (!DECL_ARTIFICIAL (arg))
-       val = iterative_hash_object (DECL_PARM_INDEX (arg), val);
+       {
+         val = iterative_hash_object (DECL_PARM_INDEX (arg), val);
+         val = iterative_hash_object (DECL_PARM_LEVEL (arg), val);
+       }
       return iterative_hash_template_arg (TREE_TYPE (arg), val);
 
     case TARGET_EXPR:
index d62d2427f1e49116d0c577f0ff08eb3b027b613a..ed4f67bbb0f08353fef56e807c4d607b35b3fb27 100644 (file)
@@ -2154,12 +2154,19 @@ cp_tree_equal (tree t1, tree t2)
 
     case PARM_DECL:
       /* For comparing uses of parameters in late-specified return types
-        with an out-of-class definition of the function.  */
-      if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
-         && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2))
-       return true;
-      else
-       return false;
+        with an out-of-class definition of the function, but can also come
+        up for expressions that involve 'this' in a member function
+        template.  */
+      if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
+       {
+         if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2))
+           return false;
+         if (DECL_ARTIFICIAL (t1)
+             || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2)
+                 && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2)))
+           return true;
+       }
+      return false;
 
     case VAR_DECL:
     case CONST_DECL:
index b23419a322c02cbafcb1c903b3ba2a62d49a02ea..8c5a37982c91ce6aea41f97f8e8d47798f415182 100644 (file)
@@ -1,5 +1,7 @@
 2011-02-26  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/template/this-targ1.C: New.
+
        * g++.dg/cpp0x/regress/template-const1.C: New.
        * g++.dg/cpp0x/regress/template-function1.C: Adjust.
        * g++.dg/template/function1.C: Adjust.
diff --git a/gcc/testsuite/g++.dg/template/this-targ1.C b/gcc/testsuite/g++.dg/template/this-targ1.C
new file mode 100644 (file)
index 0000000..6864be5
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/47904
+
+template <bool>
+struct S
+{
+};
+
+template <class T>
+class U
+{
+  T t;
+  int foo () const
+  {
+    S <sizeof (t) == 1> s;
+    return 1;
+  }
+  int bar () const
+  {
+    S <sizeof (t) == 1> s;
+    return 1;
+  }
+};
+