Patchwork C++ PATCH for c++/47950 (ICE with condition in template)

login
register
mail settings
Submitter Jason Merrill
Date March 3, 2011, 4:52 p.m.
Message ID <4D6FC748.1090909@redhat.com>
Download mbox | patch
Permalink /patch/85298/
State New
Headers show

Comments

Jason Merrill - March 3, 2011, 4:52 p.m.
On 03/03/2011 12:08 AM, Jason Merrill wrote:
> The problem here was that we were folding the initializer too many
> times, so we lost the TREE_CONSTANT on the TARGET_EXPR. Since we already
> fold in cp_parser_initializer_clause, it's redundant to do so in
> cp_parser_condition as well.

It occurred to me that a more robust fix would be to make it so 
redundant folding doesn't cause an ICE here.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit a0390d566c766d20b49735be27913666a1e7ffad
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 3 00:08:21 2011 -0500

    	PR c++/47950
    	* pt.c (tsubst_copy_and_build) [TARGET_EXPR]: Retain TREE_CONSTANT.

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4b262d0..60b2699 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13368,7 +13368,11 @@  tsubst_copy_and_build (tree t,
       /* We can get here for a constant initializer of non-dependent type.
          FIXME stop folding in cp_parser_initializer_clause.  */
       gcc_assert (TREE_CONSTANT (t));
-      return get_target_expr (RECUR (TARGET_EXPR_INITIAL (t)));
+      {
+	tree r = get_target_expr (RECUR (TARGET_EXPR_INITIAL (t)));
+	TREE_CONSTANT (r) = true;
+	return r;
+      }
 
     default:
       /* Handle Objective-C++ constructs, if appropriate.  */