From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3977E395A00B; Tue, 31 May 2022 15:42:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3977E395A00B From: "kamil.sliwak at codepoets dot it" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105794] New: Spurious "control reaches end of non-void function" warning with a combination of destructor, try/catch and if (true) Date: Tue, 31 May 2022 15:42:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kamil.sliwak at codepoets dot it X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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, 31 May 2022 15:42:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105794 Bug ID: 105794 Summary: Spurious "control reaches end of non-void function" warning with a combination of destructor, try/catch and if (true) Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kamil.sliwak at codepoets dot it Target Milestone: --- After switching to GCC 12 I noticed that in several places in the C++ proje= ct I'm working on I'm now getting the `control reaches end of non-void functio= n` warning. This seems like a regression since it's not happening with earlier= GCC versions or with latest Clang. I managed to distill the problematic code into a small repro (see below) and it's reproducible via https://godbolt.org so it does not seem dependent on = my specific environment. The original code is more complicated but in the end a combination of three things seems to be causing this: 1. A variable of a custom class type that has an explicitly defined destruc= tor (which can be empty though). 2. A try/catch block with a return. 3. A `throw` wrapped in a condition that's a compile-time constant. Removing any of the above makes the warning go away. ### Environment - GCC version: 12.1.0 - System: Arch Linux ### Repro #### Command ``` g++ test.cpp ``` #### `test.cpp` ``` #include class C { public: ~C() {} }; int foo() { C c; try { return 1; } catch (std::exception const&) { } if (true) throw std::exception(); } int main() { return 0; } ``` #### Output ``` test.cpp: In function =E2=80=98int foo()=E2=80=99: test.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type] 22 | } | ^ ```=