[Bug c++/96182] GCC accepts constexpr function with no return-statement
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jul 13 12:18:51 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96182
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
E.g.
constexpr int foo (int x) { if (x == 5) return 3; } constexpr int a = foo (5);
is accepted just with warning by both compilers and I think that is right, it
is only an error if one does constexpr int b = foo (4); or similar.
But for some reason clang treats your case differently (when there are no
return statements at all), but only in constexpr functions. Not sure how is it
backed up, unless the standard says that a constexpr function must have a
return statement or something similar, not sure if that is ok. It is true that
in these cases all invocations of such function in constant expression contexts
will result in an error, but if you don't invoke them...
More information about the Gcc-bugs
mailing list