public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rschoe at de dot ibm.com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-99938-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99938 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=50513&action=edit Code example when compiled with g++ -O1 -c code.cpp does not show any warning, 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 <cstddef> struct C { C(int *); ~C(); }; int foo() { C c = 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 <cstddef> struct C { C(int *); ~C(); }; int foo() { C c = nullptr; if(false) { while(1){} } } ``` g++ generates the following output (compiler arguments are relevant): ``` g++ -O1 -c code.cpp main.cpp: In function ‘int foo()’: main.cpp:11:11: warning: control reaches end of non-void function [-Wreturn-type] 11 | C c = 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 line 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 figure out how to add formatting (e.g. Markdown) or attach multiple files.
next reply other threads:[~2021-04-06 15:37 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-04-06 15:37 rschoe at de dot ibm.com [this message] 2021-04-06 15:41 ` [Bug c++/99938] " redi at gcc dot gnu.org 2021-04-06 15:48 ` rschoe at de dot ibm.com 2021-04-08 11:19 ` marxin at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99938-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).