aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/init.cc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2023-01-19 17:12:34 -0500
committerMarek Polacek <polacek@redhat.com>2023-01-23 16:41:48 -0500
commite3585e6acdfd5c1793f877476647d2521620c95c (patch)
treebe03840369b1fc4e087b3b97fed693bce71e861d /gcc/cp/init.cc
parent72e46b3c7ad5e3d2c69868a510c00707c356106a (diff)
downloadgcc-e3585e6acdfd5c1793f877476647d2521620c95c.zip
gcc-e3585e6acdfd5c1793f877476647d2521620c95c.tar.gz
gcc-e3585e6acdfd5c1793f877476647d2521620c95c.tar.bz2
c++: Quash bogus -Wunused-value with new [PR107797]
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.
Diffstat (limited to 'gcc/cp/init.cc')
-rw-r--r--gcc/cp/init.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index f816c47..52e96fb 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -3800,6 +3800,8 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
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). */