From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BD79E385840C; Wed, 12 Jan 2022 16:58:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD79E385840C From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103991] [12 Regression] Bogus -Wreturn-type with constexpr if and local var with destructor Date: Wed, 12 Jan 2022 16:58:40 +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: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jan 2022 16:58:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103991 --- Comment #6 from Jakub Jelinek --- For consteval if I guess we could do: --- gcc/cp/cp-objcp-common.c.jj 2022-01-11 23:11:22.091294356 +0100 +++ gcc/cp/cp-objcp-common.c 2022-01-12 17:57:18.232202275 +0100 @@ -313,6 +313,13 @@ cxx_block_may_fallthru (const_tree stmt) return false; case IF_STMT: + if (IF_STMT_CONSTEXPR_P (stmt)) + { + if (integer_nonzerop (IF_COND (stmt))) + return block_may_fallthru (THEN_CLAUSE (stmt)); + if (integer_zerop (IF_COND (stmt))) + return block_may_fallthru (ELSE_CLAUSE (stmt)); + } if (block_may_fallthru (THEN_CLAUSE (stmt))) return true; return block_may_fallthru (ELSE_CLAUSE (stmt)); --- gcc/cp/cp-gimplify.c.jj 2022-01-11 23:11:22.090294370 +0100 +++ gcc/cp/cp-gimplify.c 2022-01-12 17:53:57.431036236 +0100 @@ -166,8 +166,13 @@ genericize_if_stmt (tree *stmt_p) can contain unfolded immediate function calls, we have to discard the then_ block regardless of whether else_ has side-effects or not. = */ if (IF_STMT_CONSTEVAL_P (stmt)) - stmt =3D build3 (COND_EXPR, void_type_node, boolean_false_node, - void_node, else_); + { + if (block_may_fallthru (then_)) + stmt =3D build3 (COND_EXPR, void_type_node, boolean_false_node, + void_node, else_); + else + stmt =3D else_; + } else stmt =3D build3 (COND_EXPR, void_type_node, cond, then_, else_); protected_set_expr_location_if_unset (stmt, locus);=