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
Details
Diff Detail
Diff Detail
Event Timeline
| clang/test/AST/Interp/records.cpp | ||
|---|---|---|
| 260 | We should test that the initialization actually happened. | |
| 262 | 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 memberor 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 memberor 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 | |
Comment Actions
The tests you proposed need https://reviews.llvm.org/D143480 first so we can cast up more than one level.
Comment Actions
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 | ||
|---|---|---|
| 256 | These lines are added by https://reviews.llvm.org/D143480 now, but the tests are left commented since they require this patch as well. | |
These lines are added by https://reviews.llvm.org/D143480 now, but the tests are left commented since they require this patch as well.