]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/47904 (ICE with DECL_PARM_INDEX (this) in cp_tree_equal)
authorJason Merrill <jason@redhat.com>
Sun, 27 Feb 2011 17:11:19 +0000 (12:11 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 27 Feb 2011 17:11:19 +0000 (12:11 -0500)
PR c++/47904
* tree.c (cp_tree_equal) [PARM_DECL]: Don't crash on
DECL_ARTIFICIAL parms.

From-SVN: r170544

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

index ac768737bd1816d8cf715979be011fe23e3ed0b3..663d4caaaa6f81e5c44d435f7e7c997ccbdc4834 100644 (file)
@@ -1,3 +1,9 @@
+2011-02-26  Jason Merrill  <jason@redhat.com>
+
+       PR c++/47904
+       * tree.c (cp_tree_equal) [PARM_DECL]: Don't crash on
+       DECL_ARTIFICIAL parms.
+
 2010-12-16  Release Manager
 
        * GCC 4.5.2 released.
index 54b76a8503072f60417928de6f311aa58975bc79..994056d9ca3deef02c98abc6b16aedf0940671af 100644 (file)
@@ -2089,12 +2089,18 @@ 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_INDEX (t1) == DECL_PARM_INDEX (t2))
+           return true;
+       }
+      return false;
 
     case VAR_DECL:
     case CONST_DECL:
index ccda4effcd000961d021c0b5b92e758b87c3337b..5055e516c98ced068fb1f5f3d87a87dc5d593e69 100644 (file)
@@ -1,3 +1,7 @@
+2011-02-26  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/template/this-targ1.C: New.
+
 2011-02-19  Alexandre Oliva  <aoliva@redhat.com>
 
        PR tree-optimization/46620
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;
+  }
+};
+