But it compiles in gcc 4.9.0. See live example:
#include <iostream>
struct A {
constexpr A(): i(5) {}
int&& f() { return std::move(i); }
int i;
} a;
A&& f(A& a) { return std::move(a); }
int main() {
A a;
int b[a.f()]{ 0, 1, 2, 3, 4 };
std::cout << b[4] << '\n';
}
From §5.19/3 we have:
An integral constant expression is an expression of integral or unscoped enumeration type, implicitly converted to a prvalue, where the converted expression is a core constant expression. [ Note: Such expressions may be used as array bounds (8.3.4, 5.3.4), as bit-field lengths (9.6), as enumerator initializers if the underlying type is not fixed (7.2), and as alignments (7.6.2). —end note]
The expression a.f()
is an expression of integral type. It seems to me (although I need some clarification on this point) that this expression is also convertible to a prvalue, because it is an xvalue. But I think the real problem here is that the expression a.f()
is not a core constant expression, as it satisfies bullet point (2.1) in §5.19/2.
§5.19/2:
A conditional-expression
e
is a core constant expression unless the evaluation ofe
, following the rules of the abstract machine (1.9), would evaluate one of the following expressions:(2.1) —
this
(5.1.1), except in aconstexpr
function or a constexpr constructor that is being evaluated as part ofe
;