[Bug c++/96182] New: GCC accepts constexpr function with no return-statement
haoxintu at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jul 13 11:52:14 GMT 2020
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
More information about the Gcc-bugs
mailing list