[Bug c++/96182] GCC accepts constexpr function with no return-statement

haoxintu at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jul 13 12:09:15 GMT 2020


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

--- Comment #2 from Haoxin Tu <haoxintu at gmail dot com> ---
(In reply to Jakub Jelinek from comment #1)
> The difference is that in C++11 the standard requires that the body of a
> constexpr function is return expression, that is not the case of C++14
> anymore.
> And, you'd get an error if you tried constexpr int a = foo (); i.e. when it
> is evaluated in constant expression, but when it is only evaluated e.g. in
> int b = foo (); it is a problem only at runtime.

Thank you, Jakub.

At runtime this must be a error. But I guess should it be rejected at compile
time?

Maybe reject this in compile time will help users to fix this issue early, like
other mainstream compilers do. Just for a suggestion, please understand if
anything I stated is unsuitable.

Thanks.


More information about the Gcc-bugs mailing list