https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107797
Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org Status|NEW |ASSIGNED --- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> --- This seems to work: diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index 0cbfd8060cb..d1e34d7de1a 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -711,8 +711,11 @@ ocp_convert (tree type, tree expr, int convtype, int flags, 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); + if (warning_suppressed_p (expr, OPT_Wunused_value)) + suppress_warning (e, OPT_Wunused_value); + return e; } complete_type (type); diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index f816c474cef..52e96fbe590 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). */