This should compile with C++20 but it doesn’t. (The uninitialized value error is incorrect since the value is only written to while it is uninitialized)
#include <array>
struct vector
{
std::array<int,3> a_;
};
constexpr auto create(int a, int b, int c) -> vector
{
vector v;
v.a_[0] = a;
v.a_[1] = b;
v.a_[2] = c;
return v;
}
auto f()
{
constexpr vector v = create(3,4,4);
}
I talked with engineering, but they believe the compiler error message is correct.
From engineering:
Evaluating v.a_[0] = a; involves calling operator[] on the uninitialized std::array subobject. It’s the call to the member function that is problematic and resulting in the error.