From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 493FB3857419; Tue, 19 Apr 2022 09:55:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 493FB3857419 From: "kdevel at vogtner dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/43943] "warning: no return statement in function returning non-void" should be an error Date: Tue, 19 Apr 2022 09:55:16 +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: unknown X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: kdevel at vogtner dot de X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: WORKSFORME 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: 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: Tue, 19 Apr 2022 09:55:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D43943 Stefan changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kdevel at vogtner dot de --- Comment #8 from Stefan --- (In reply to Jonathan Wakely from comment #4) > There are cases which are either not diagnosable or cannot be > written, such as this example from Doug Gregor: >=20 > in generic code, there might not be a way to create a value with the > appropriate type. For example: >=20 > template > T maybe_call(std::function f) { > if (f) > return f(); > else > abort_program(); >=20 > // Cannot write a return here, because we have no way to > create a value of type 'T' > } One can of course write a return there: template T maybe_call(std::function f) { if (f) return f(); else abort_program(); // Cannot write a return here, because we have no way to create a val= ue of type 'T' return f(); } which refactors nicely into template T maybe_call(std::function f) { if (! f) abort_program(); return f(); }=