Taking the address of a literal, not a `constexpr`

Viewed 262

Strictly according to the rules of C++14, at least the ones given by cppreference.com, isn't the line (1) a constant expression?

constexpr const int* addr(const int& ir) { return &ir; }
constexpr const int* tp = addr(5); // (1)

It's true that is not an address constant expression, because &ir isn't the address of a static object (&ir is the address of a temporary in this context, which cannot be known in compilation-time).

But it is a core constant expression because it doesn't violate any of the back-listed rules of core constant expression, which has no back-listed rules about getting the address of an object.

1 Answers
Related