As explained in this page , the constexpr compound body operator, if it is not removed or not installed by default, must satisfy the constexpr function body constexpr , that is, it can contain any statements except:
- ad
asm - a
goto statement - a
try -block - definition of a variable of non-literal type or static or duration of storage of flows or for which initialization is not performed
It seems that the standard does not limit the number of return that may appear, while in C ++ 11 only one is allowed.
Now consider the following code:
class Thing { public:
Clang (3.5 with -std = C ++ 14) compiles it in order, but GCC (4.9.1 with -std = C ++ 14) does not complain:
Constexpr constructor has no empty body
However, if it is modified:
class Thing { public:
Then it compiles under both compilers.
Since the GCC complains that the constructor body is not empty, should it also complain in a later case? Is this behavior a bug in GCC? Is the return statement valid for constexpr constructors?
Note: whether a single return really worth it is not a question of this question, although it is interesting and maybe worth another. I put single return into constructors whose body is empty, for style reasons.
source share