CheckDesignatedInitializer wasn't taking into account the base classes when computing the index for the field in the derived class, which caused the test case to crash during IRGen because of a malformed AST.
Details
Diff Detail
Event Timeline
What happens with virtual bases?
struct B { int x; }; struct D : virtual B { int y; }; void test() { D d = {1, .y = 2}; }
lib/Sema/SemaInit.cpp | ||
---|---|---|
2250 | Do this before counting fields, IMO it's more intuitive. | |
test/SemaCXX/designated-initializers-base-class.cpp | ||
1 | This might be less fragile as an IRGen test. Alternatively, this is a good expected-no-diagnostic test: void test() { D d = {1, .y = 2}; } Right now we emit warning: initializer overrides prior initialization of this subobject, which is obviously wrong. |
A class with virtual base is not considered an aggregate, so it doesn't go through aggregate initialization (and therefore it doesn't enter CheckDesignatedInitializer). Instead, in TryListInitialization, it tries to find a matching constructor of D and fails.
test/SemaCXX/designated-initializers-base-class.cpp | ||
---|---|---|
1 | good idea. |
Do this before counting fields, IMO it's more intuitive.