From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F0963858C53; Thu, 19 Jan 2023 19:03:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F0963858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674154981; bh=UN6olPLQiC3KmNRsK5VQ+40oTBBi3eloVSn+rSfnz8c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nRTHKpH3E20iDpfa/bUXHsOOEtkGI73uq3/tgWf2zn9+E9jbxYWjIpp0P5f07r6It eQfdzAaW/EgN9cu3TK0nFo1HTHPH5JJ6O6B0ZOUVJemg+6A+TAykPMV/ros5Xy1C4g Tu5zu5jOnl/BHkUlsH94YU5wWCKyko/3DCbiD0CY= From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107797] "warning right operand of comma operator has no effect" for expressions with no comma operator Date: Thu, 19 Jan 2023 19:03:00 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mpolacek at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: assigned_to bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107797 Marek Polacek 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 --- 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 =3D=3D TREE_OPERAND (expr, 1)) return expr; - return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (e= ), - TREE_OPERAND (expr, 0), e); + e =3D 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 **placement, tree type, tree nelts, if (cookie_expr) rval =3D build2 (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval); + suppress_warning (rval, OPT_Wunused_value); + if (rval =3D=3D data_addr && TREE_CODE (alloc_expr) =3D=3D 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). */=