https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114409

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
The question is what handles the COMPOUND_EXPR with DECL_EXPR when the
ANNOTATE_EXPR isn't around.  tsubst_expr doesn't handle DECL_EXPRs.

It's built even w/o the #pragma via finish_cond and finish_while_stmt_cond
and in that case it's tsubst_stmt that handles the COMPOUND_EXPR and
that function does handle DECL_EXPRs.  Maybe ANNOTATE_EXPR should be handled
at the "stmt" level [as well]?  Or the COMPOUND_EXPR handling in
tsubst_expr should recurse to tsubst_stmt?

That said, ( DECL_EXPR <X>, .. use of X ) is phishy?

Jason?

The following fixes it:

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index bf4b89d8413..dae423a751f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20635,8 +20635,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t
complain, tree in_decl)

     case COMPOUND_EXPR:
       {
-       tree op0 = tsubst_expr (TREE_OPERAND (t, 0), args,
+       tree op0 = tsubst_stmt (TREE_OPERAND (t, 0), args,
                                complain & ~tf_decltype, in_decl);
+       if (op0 == NULL_TREE)
+         /* If the first operand was a statement, we're done with it.  */
+         RETURN (RECUR (TREE_OPERAND (t, 1)));
        RETURN (build_x_compound_expr (EXPR_LOCATION (t),
                                       op0,
                                       RECUR (TREE_OPERAND (t, 1)),

Reply via email to