I came across this strange behavior and I can't find a good explanation of it.
The code below will compile successfully before c++20 and only fail if explicit is used.
struct Square {
int area = 10;
Square() = default; // only if this is explicit will the compile fail
Square(const Square& other) = delete;
Square(Square&& other) = delete;
Square& operator =(Square&& square) = delete;
Square& operator =(const Square& square) = delete;
};
int main() {
Square s = {
.area = 10
};
}
Which is strange on its own but turning the compiler to c++20 will make the above code fail with these error messages
gcc
could not convert brace-enclosed initializer list
clang
no matching constructor for initialization of 'Square'
Question:
Why does it compile successfully before c++20 unless
explicit? In other words what implicit conversion takes place to make that happen?What changed in c++20 that made this code fail to compile?