From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C41663844046; Tue, 6 Apr 2021 15:37:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C41663844046 From: "rschoe at de dot ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99938] New: Non-void function with no return statement: Either no or misleading warning is printed Date: Tue, 06 Apr 2021 15:37:23 +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: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rschoe at de dot ibm.com 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 attachments.created 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, 06 Apr 2021 15:37:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99938 Bug ID: 99938 Summary: Non-void function with no return statement: Either no or misleading warning is printed Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rschoe at de dot ibm.com Target Milestone: --- Created attachment 50513 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50513&action=3Dedit Code example when compiled with g++ -O1 -c code.cpp does not show any warni= ng, If you exchange NULL with nullptr, warning shows wrong line Hi, Tested this with g++ (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9) uname -r 5.10.19-200.fc33.x86_64 The following code ``` #include struct C { C(int *); ~C(); }; int foo() { C c =3D NULL; if(false) { while(1){} } } ``` compiled with `g++ -O1 -c code.cpp` (compiler arguments are relevant) does not generate any warning about missing return statement in `foo()` however when modified slightly (change `NULL` to `nullptr`): ``` #include struct C { C(int *); ~C(); }; int foo() { C c =3D nullptr; if(false) { while(1){} } } ``` g++ generates the following output (compiler arguments are relevant): ``` g++ -O1 -c code.cpp main.cpp: In function =E2=80=98int foo()=E2=80=99: main.cpp:11:11: warning: control reaches end of non-void function [-Wreturn-type] 11 | C c =3D nullptr; | ^~~~~~~ ``` which detects the missing `return` but points to the wrong line. I expected line 16 (the closing bracket of foo() function scope) to be called out. Other modifications which lead to the warning being printed with correct li= ne number (16) are (applying one at a time is sufficient): - Compile with `-O0` - Comment/remove the `while(1){}` - Comment/remove the desctuctor `~C` declaration clang prints warnings with correct line (16) in all cases. I would expect g= ++ to behave the same. ---- Excuse me if I overlooked something or misunderstood c++ or the concept of = g++. If this is intended behavior, I would be happy to learn more about it :) Also I had some trouble formatting this bug report. Somehow I could not fig= ure out how to add formatting (e.g. Markdown) or attach multiple files.=