For the given test case, we were trying to initialize a member of C, which doesn't have any. Get the proper base pointer instead and initialize the members there.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/test/AST/Interp/records.cpp | ||
---|---|---|
258 | We should test that the initialization actually happened. | |
260 | Another test would be for invalid base initialization, like: struct Base { int a; }; struct Intermediate : Base { int b; }; struct Final : Intermediate { int c; constexpr Final(int a, int b, int c) : c(c) {} }; static_assert(Final{1, 2, 3}.c == 3, ""); // OK static_assert(Final{1, 2, 3}.a == 0, ""); // Error, reads uninitialized member or with multiple bases: struct Base { int a; }; struct Mixin { int b; constexpr Mixin() = default; constexpr Mixin(int b) : b(b) {} }; struct Final : Base, Mixin { int c; constexpr Final(int a, int b, int c) : Mixin(b), c(c) {} constexpr Final(int a, int b, int c, bool) : c(c) {} }; static_assert(Final{1, 2, 3}.c == 3, ""); // OK static_assert(Final{1, 2, 3}.b == 2, ""); // OK static_assert(Final{1, 2, 3}.a == 0, ""); // Error, reads uninitialized member or in a different form: struct Base { int a; }; struct Mixin { int b; }; struct Final : Base, Mixin { int c; constexpr Final(int a, int b, int c) : c(c) { this->b = b; } constexpr Final(int a, int b, int c, bool) : c(c) {} }; static_assert(Final{1, 2, 3}.c == 3, ""); // OK static_assert(Final{1, 2, 3}.b == 2, ""); // OK static_assert(Final{1, 2, 3}.a == 0, ""); // Error, reads uninitialized member |
The tests you proposed need https://reviews.llvm.org/D143480 first so we can cast up more than one level.
Okay, how about we land that one first then come back to this one? I left some comments on the other review.
clang/test/AST/Interp/records.cpp | ||
---|---|---|
271 | These lines are added by https://reviews.llvm.org/D143480 now, but the tests are left commented since they require this patch as well. |
We should test that the initialization actually happened.