public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96182] New: GCC accepts constexpr function with no return-statement
@ 2020-07-13 11:52 haoxintu at gmail dot com
  2020-07-13 11:59 ` [Bug c++/96182] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: haoxintu at gmail dot com @ 2020-07-13 11:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96182

            Bug ID: 96182
           Summary: GCC accepts constexpr function with no
                    return-statement
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haoxintu at gmail dot com
  Target Milestone: ---

Hi,all.

This code, test.cc, is an invalid code I guess, but GCC accepts it.

$cat test.cc
constexpr int
foo()
{}

$g++ test.cc
test.cc: In function ‘constexpr int foo()’:
test.cc:3:2: warning: no return statement in function returning non-void
[-Wreturn-type]
    3 | {}
      |  ^

GCC only emits normal -Wreturn-type warning and then accepts it.

Weirdly, this code is rejected under -std=c++11.

$g++ -std=c++11 test.cc
test.cc: In function ‘constexpr int foo()’:
test.cc:3:2: error: body of ‘constexpr’ function ‘constexpr int foo()’ not a
return-statement
    3 | {}
      |  ^
test.cc:3:2: warning: no return statement in function returning non-void
[-type-Wreturn-type]

I think constexpr function is not a deprecated feature in c++14. I also test
this in Clang, it is rejected by both standards.

Every GCC versions from 5.1 to trunk behave the same.

Thanks,
Haoxin

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-28  0:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 11:52 [Bug c++/96182] New: GCC accepts constexpr function with no return-statement haoxintu at gmail dot com
2020-07-13 11:59 ` [Bug c++/96182] " jakub at gcc dot gnu.org
2020-07-13 12:09 ` haoxintu at gmail dot com
2020-07-13 12:18 ` jakub at gcc dot gnu.org
2020-07-13 12:21 ` jakub at gcc dot gnu.org
2020-07-13 12:28 ` redi at gcc dot gnu.org
2020-07-13 12:36 ` jakub at gcc dot gnu.org
2020-07-31 21:08 ` cvs-commit at gcc dot gnu.org
2021-08-28  0:03 ` pinskia at gcc dot gnu.org

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).