[This question arised from this question]
Consider the following program:
#include <iostream>
struct Foo
{
const size_t size;
int* arr{ create_arr(size) };
Foo(size_t s)
: size{ set_size(s) }
{
}
static int* create_arr(size_t s)
{
std::cout << "Creating array with size " << s << '\n';
return new int[s];
}
static size_t set_size(size_t s)
{
std::cout << "Setting size to " << s << '\n';
return s;
}
};
int main()
{
Foo f(10);
}
The inline initialization of arr depends on the value of size. But the value of size is only initialized in the constructor initializer list.
Both GCC and Clang handles it correctly, and will complain if the declaration order of size and arr is mirrored. I've also heard that MSVC will do the "right" thing (according to comments in the other question).
My question is: Is this well-defined?
I know that initialization is done in declaration order, but does it include inline initialization as well?