Commit 507318f1 by Jason Merrill Committed by Jason Merrill

PR c++/86485 - -Wmaybe-unused with empty class ?:

The problem in this testcase is that the front end expects an rvalue
COND_EXPR to initialize a single temporary from one of the arms.  But
because gimplify_cond_expr used MODIFY_EXPR, instead the arms would each
create their own temporary and then copy that into the common temporary.

So, let's use INIT_EXPR instead.

	* gimplify.c (gimplify_cond_expr): Use INIT_EXPR.

From-SVN: r269403
parent dbcd32f8
2019-03-02 Jason Merrill <jason@redhat.com>
PR c++/86485 - -Wmaybe-unused with empty class ?:
* gimplify.c (gimplify_cond_expr): Use INIT_EXPR.
2019-03-05 Jakub Jelinek <jakub@redhat.com> 2019-03-05 Jakub Jelinek <jakub@redhat.com>
PR target/89587 PR target/89587
......
...@@ -4024,11 +4024,11 @@ gimplify_cond_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback) ...@@ -4024,11 +4024,11 @@ gimplify_cond_expr (tree *expr_p, gimple_seq *pre_p, fallback_t fallback)
/* Build the new then clause, `tmp = then_;'. But don't build the /* Build the new then clause, `tmp = then_;'. But don't build the
assignment if the value is void; in C++ it can be if it's a throw. */ assignment if the value is void; in C++ it can be if it's a throw. */
if (!VOID_TYPE_P (TREE_TYPE (then_))) if (!VOID_TYPE_P (TREE_TYPE (then_)))
TREE_OPERAND (expr, 1) = build2 (MODIFY_EXPR, type, tmp, then_); TREE_OPERAND (expr, 1) = build2 (INIT_EXPR, type, tmp, then_);
/* Similarly, build the new else clause, `tmp = else_;'. */ /* Similarly, build the new else clause, `tmp = else_;'. */
if (!VOID_TYPE_P (TREE_TYPE (else_))) if (!VOID_TYPE_P (TREE_TYPE (else_)))
TREE_OPERAND (expr, 2) = build2 (MODIFY_EXPR, type, tmp, else_); TREE_OPERAND (expr, 2) = build2 (INIT_EXPR, type, tmp, else_);
TREE_TYPE (expr) = void_type_node; TREE_TYPE (expr) = void_type_node;
recalculate_side_effects (expr); recalculate_side_effects (expr);
......
// PR c++/86485
// { dg-additional-options -Wmaybe-uninitialized }
struct E {};
struct S { S () {} E e; };
void foo (S);
void
bar (bool b)
{
foo (b ? S () : S ());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment