This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix c++/17404


I would like to take a moment to complain about the collection of

	tsubst_copy
	tsubst_expr
	tsubst_copy_and_build

all of which do some portion of expression template instantiation.
I'm not sure why we don't have *everything* instantiated by, say,
"tsubst".  Which is not mentioned above because it deals only with
types.  Obviously.  As for "tsubst_expr", it deals primarily, though
not exclusively, with statements instead of expressions.

Anyway, statement expression expansion was being done in the wrong
place.  As demonstrated by the testcase.


r~



	* pt.c (cur_stmt_expr): Move from tsubst_expr.
	(tsubst_expr) <case STMT_EXPR>: Move ...
	(tsubst_copy_and_build): ... here.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.920
diff -u -p -r1.920 pt.c
--- cp/pt.c	10 Sep 2004 23:56:31 -0000	1.920
+++ cp/pt.c	12 Sep 2004 03:49:59 -0000
@@ -67,6 +67,11 @@ static GTY(()) tree current_tinst_level;
 
 static GTY(()) tree saved_access_scope;
 
+/* Live only within one (recursive) call to tsubst_expr.  We use
+   this to pass the statement expression node from the STMT_EXPR
+   to the EXPR_STMT that is its result.  */
+static tree cur_stmt_expr;
+
 /* A map from local variable declarations in the body of the template
    presently being instantiated to the corresponding instantiated
    local variables.  */
@@ -7790,11 +7795,6 @@ tsubst_copy (tree t, tree args, tsubst_f
 static tree
 tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 {
-  /* Live only within one (recursive) call to tsubst_expr.  We use
-     this to pass the statement expression node from the STMT_EXPR
-     to the EXPR_STMT that is its result.  */
-  static tree cur_stmt_expr;
-
   tree stmt, tmp;
 
   if (t == NULL_TREE || t == error_mark_node)
@@ -7825,19 +7825,6 @@ tsubst_expr (tree t, tree args, tsubst_f
 				       args, complain, in_decl));
       break;
 
-    case STMT_EXPR:
-      {
-	tree old_stmt_expr = cur_stmt_expr;
-	tree stmt_expr = begin_stmt_expr ();
-
-	cur_stmt_expr = stmt_expr;
-	tsubst_expr (STMT_EXPR_STMT (t), args, complain, in_decl);
-	stmt_expr = finish_stmt_expr (stmt_expr, false);
-	cur_stmt_expr = old_stmt_expr;
-
-	return stmt_expr;
-      }
-
     case EXPR_STMT:
       tmp = tsubst_expr (EXPR_STMT_EXPR (t), args, complain, in_decl);
       if (EXPR_STMT_STMT_EXPR_RESULT (t))
@@ -8626,6 +8613,19 @@ tsubst_copy_and_build (tree t, 
     case OFFSETOF_EXPR:
       return fold_offsetof (RECUR (TREE_OPERAND (t, 0)));
 
+    case STMT_EXPR:
+      {
+	tree old_stmt_expr = cur_stmt_expr;
+	tree stmt_expr = begin_stmt_expr ();
+
+	cur_stmt_expr = stmt_expr;
+	tsubst_expr (STMT_EXPR_STMT (t), args, complain, in_decl);
+	stmt_expr = finish_stmt_expr (stmt_expr, false);
+	cur_stmt_expr = old_stmt_expr;
+
+	return stmt_expr;
+      }
+
     default:
       return tsubst_copy (t, args, complain, in_decl);
     }
Index: testsuite/g++.dg/template/stmtexpr1.C
===================================================================
RCS file: testsuite/g++.dg/template/stmtexpr1.C
diff -N testsuite/g++.dg/template/stmtexpr1.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/template/stmtexpr1.C	12 Sep 2004 04:43:08 -0000
@@ -0,0 +1,10 @@
+// PR c++/17404
+// { dg-do compile }
+// { dg-options "" }
+
+template <int> void foo ()
+{
+  __builtin_expect  (({0;}), 1);
+}
+ 
+template void foo<1> ();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]