Given the following code (it compiles successfully):
int main(void)
{
const int a{};
const int &r = a;
static int arr[1] = {r};
constexpr const int &ref = arr[0]; // OK
}
The initialization of ref
is glvalue designating reference ref
. So the full-expression of the initialization has to be a glvalue core constant expression. That's, the reference ref
has to refer to an entity that's a permitted result of a constant expression (object with static storage duration). It refers to the element arr[0]
which is of type int
. Here's my question: Is this element a subobject with static storage duration? if yes, what's the wording that states that?
CodePudding user response:
Here's my question: Is this element a subobject with static storage duration?
[basic.stc.inherit]/1 says:
The storage duration of subobjects and reference members is that of their complete object.
An array element is a subobject of the array it is an element of. So it has the same storage duration as the array.