We shouldn't emit "right operand of comma operator has no effect"
when that comma operator was created by the compiler for "new int{}".
convert_to_void/COMPOUND_EXPR already checks warning_suppressed_p so
we can just suppress -Wunused-value.
PR c++/107797
gcc/cp/ChangeLog:
* cvt.cc (ocp_convert): copy_warning when creating a new
COMPOUND_EXPR.
* init.cc (build_new_1): Suppress -Wunused-value on
compiler-generated COMPOUND_EXPRs.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wunused-value-1.C: New test.
return error_mark_node;
if (e == TREE_OPERAND (expr, 1))
return expr;
- return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e),
- TREE_OPERAND (expr, 0), e);
+ e = build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e),
+ TREE_OPERAND (expr, 0), e);
+ copy_warning (e, expr);
+ return e;
}
complete_type (type);
if (cookie_expr)
rval = build2 (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval);
+ suppress_warning (rval, OPT_Wunused_value);
+
if (rval == data_addr && TREE_CODE (alloc_expr) == TARGET_EXPR)
/* If we don't have an initializer or a cookie, strip the TARGET_EXPR
and return the call (which doesn't need to be adjusted). */
--- /dev/null
+// PR c++/107797
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wunused" }
+
+void
+g ()
+{
+ (long) new int{};
+ long(new int{});
+ (long) new int();
+ long(new int());
+}