From: Jason Merrill Date: Sun, 27 Feb 2011 08:13:28 +0000 (-0500) Subject: re PR c++/47904 (ICE with DECL_PARM_INDEX (this) in cp_tree_equal) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e7dc5734a82ce4794027871556dfdd4bf1be2c25;p=gcc.git re PR c++/47904 (ICE with DECL_PARM_INDEX (this) in cp_tree_equal) PR c++/47904 * tree.c (cp_tree_equal): Compare DECL_PARM_LEVEL. * pt.c (iterative_hash_template_arg): And hash it. From-SVN: r170533 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 828336212b3..50e4b48d5ea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2011-02-26 Jason Merrill + 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. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ed9d28b0b2f..4b262d00016 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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: diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index d62d2427f1e..ed4f67bbb0f 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b23419a322c..8c5a37982c9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2011-02-26 Jason Merrill + * 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 index 00000000000..6864be5abbc --- /dev/null +++ b/gcc/testsuite/g++.dg/template/this-targ1.C @@ -0,0 +1,23 @@ +// PR c++/47904 + +template +struct S +{ +}; + +template +class U +{ + T t; + int foo () const + { + S s; + return 1; + } + int bar () const + { + S s; + return 1; + } +}; +