From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7C04D3943545; Wed, 12 Jan 2022 16:33:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C04D3943545 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:33:25 +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: cc 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:33:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103991 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- For IF_STMT_CONSTEXPR_P and IF_STMT_CONSTEVAL_P IF_STMTs, it is unclear wha= t we should do, because in either case we throw away the other branch if any. Either we do for those what we used to do before r12-5638 and risk -Wunreachable-code warnings (when/if it is readded), e.g. on code like: if constexpr (true) return 0; some code; but we don't emit these -Wreturn-type false positives in cases where the untaken block of code doesn't fall through. Or the r12-5638 can result in such false positives. Or perhaps we should track if we had the other block of code at all (if not= , it is ok to do what we do right now) and if possible otherwise try to figure o= ut if the other block could fall through and if it can't, perhaps replace the void_node with __builtin_unreachable () call? For IF_STMT_CONSTEVAL_P we still have the other branch around and could per= haps call block_may_fallthru on it, but for IF_STMT_CONSTEXPR_P we discard it earlier, outside of templates already during parsing. Now, as Richi's warning isn't in GCC 12, quickest/safest temporary fix woul= d be to revert to previous behavior for IF_STMT_CONSTEXPR_P and IF_STMT_CONSTEVA= L_P, if (IF_STMT_CONSTEVAL_P (stmt)) stmt =3D else_; else if (IF_STMT_CONSTEXPR_P (stmt)) stmt =3D integer_nonzerop (cond) ? then_ ? else_; else stmt =3D build3 (COND_EXPR, void_type_node, cond, then_, else_); Jason, thoughts on this?=