From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3DFED3858D28; Fri, 31 Mar 2023 23:24:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DFED3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680305090; bh=Nva5YX9aGN2dNYJtVqzXhFM2r02t8Vp2kgLNLcPGVdQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=reB8EIfM6GQC7L0n+/a1byVeHkXfczxzXqpMJLXEg7n/AXvXdCRTi5GvjikUxyn7Y /WIQZiJYAYQouugObx+gqvrPmVW746Vr7QbZFBRGNoL7kvrKEhhmkbMrYTatQktjVy Yuo/C175mYH9N/XS4jiqjsgrdlUoDz3UmtdvhMxc= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109364] Missing return statement in a non void function gives only a warning but produces a forced crash. Date: Fri, 31 Mar 2023 23:24:50 +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: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: DUPLICATE X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109364 --- Comment #11 from Jonathan Wakely --- I already explained this on reddit, and it's already explained in PR 43943. There are programs that are valid and must not give an error. int f() { } int main() { } This never calls f() so there is no problem. -Werror=3Dreturn-type would fa= il to compile this valid program. int g(bool b) { if (b) return 1; } int main() { g(true); } This program calls g(true) which is OK, it never calls g(false). -Werror=3Dreturn-type would fail to compile this valid program. The C++ standard says these programs must be accepted without errors. What = GCC does is allow you to compile broken code, but it warns, and since GCC 13 it tries to prevent completely unpredictable undefined behaviour if you accidentally do fall off the end of a function without returning.=