Open
Description
The following code does not build:
#include <variant>
struct X {
struct A { int a=0; };
struct B {
std::variant<X::A> a;
};
};
void test() {
X::B b;
}
See https://godbolt.org/z/4ExGEvTf6 (on clang-trunk, with -std=c++20 -O2).
The error is:
<source>:11:10: error: call to implicitly-deleted default constructor of 'X::B'
11 | X::B b;
| ^
<source>:6:28: note: default constructor of 'B' is implicitly deleted because field 'a' has no default constructor
6 | std::variant<X::A> a;
| ^
Each of the following changes will make the code compile:
- making A and B top-level classes
- Changing class A to not have an initializer for a
- Changing class A to have an explicit constructor (like
A() : a(0) {}
)
I think this code should be accepted. GCC accepts this code since version 14.1 (previous versions reject it with an error message similar to clang's message).