Is it permitted to declare a non-const reference as constexpr
? Example code:
int x = 1;
constexpr int& r = x;
This is accepted by gcc and clang (I tried several current and past versions of both, back to C++11, and all accepted it). However I think it should not be accepted because C++14 [dcl.constexpr/9] says:
if a constexpr specifier is used in a reference declaration, every full- expression that appears in its initializer shall be a constant expression
and x
is not a constant expression.
The language in the latest C++17 draft of [dcl.constexpr] changed and doesn't even mention constexpr
references explicitly any more, I can't make head nor tail of what it is trying to say about them.