* semantics.c (begin_stmt_expr): Avoid duplicating the effect of
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 28 Apr 1998 13:24:00 +0000 (13:24 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 28 Apr 1998 13:24:00 +0000 (13:24 +0000)
the expression in templates.
(finish_stmt_expr): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@19469 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C [new file with mode: 0644]

index b883155..c9c51bb 100644 (file)
@@ -1,3 +1,9 @@
+Tue Apr 28 13:22:01 1998  Mark Mitchell  <mmitchell@usa.net>
+
+       * semantics.c (begin_stmt_expr): Avoid duplicating the effect of
+       the expression in templates.
+       (finish_stmt_expr): Likewise.
+
 1998-04-28  Brendan Kehoe  <brendan@cygnus.com>
 
        * decl2.c (ambiguous_decl): Fix NAME parm to be a tree, not int.
index d43e611..e7b738a 100644 (file)
@@ -761,14 +761,18 @@ finish_parenthesized_expr (expr)
   return expr;
 }
 
-/* Begin a statement-expression.  Returns a new RTL_EXPR if
-   appropriate. */
+/* Begin a statement-expression.  The value returned must be passed to
+   finish_stmt_expr.  */
 
 tree 
 begin_stmt_expr ()
 {
   keep_next_level ();
-  return processing_template_decl ? NULL_TREE : expand_start_stmt_expr(); 
+  /* If we're processing_template_decl, then the upcoming compound
+     statement will be chained onto the tree structure, starting at
+     last_tree.  We return last_tree so that we can later unhook the
+     compound statement.  */
+  return processing_template_decl ? last_tree : expand_start_stmt_expr(); 
 }
 
 /* Finish a statement-expression.  RTL_EXPR should be the value
@@ -807,6 +811,14 @@ finish_stmt_expr (rtl_expr, expr)
     }
   else
     result = expr;
+
+  if (processing_template_decl)
+    {
+      /* Remove the compound statement from the tree structure; it is
+        now saved in the BIND_EXPR.  */
+      last_tree = rtl_expr;
+      TREE_CHAIN (last_tree) = NULL_TREE;
+    }
   
   return result;
 }
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C b/gcc/testsuite/g++.old-deja/g++.pt/stmtexpr2.C
new file mode 100644 (file)
index 0000000..475ad72
--- /dev/null
@@ -0,0 +1,24 @@
+extern "C" void abort();
+
+int i;
+
+void g()
+{
+  i++;
+}
+
+template <class T>
+void f(T)
+{
+  __extension__ ({g();});
+}
+
+int main()
+{
+  f(3.0);
+  if (i != 1)
+    abort();
+
+  return 0;
+}