Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/test/AST/Interp/records.cpp
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | constexpr int m() const { | ||||
return 1; | return 1; | ||||
} | } | ||||
}; | }; | ||||
constexpr S s; | constexpr S s; | ||||
static_assert(s.m() == 1, ""); | static_assert(s.m() == 1, ""); | ||||
#if __cplusplus >= 201703L | #if __cplusplus >= 201703L | ||||
namespace BaseInit { | namespace BaseInit { | ||||
class _A {public: int a;}; | |||||
class _B : public _A {}; | |||||
class _C : public _B {}; | |||||
aaron.ballman: We should test that the initialization actually happened. | |||||
constexpr _C c{12}; | |||||
constexpr const _B &b = c; | |||||
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 aaron.ballman: Another test would be for invalid base initialization, like:
```
struct Base {
int a;
}… | |||||
static_assert(b.a == 12); | |||||
class A {public: int a;}; | class A {public: int a;}; | ||||
class B : public A {}; | class B : public A {}; | ||||
class C : public A {}; | class C : public A {}; | ||||
class D : public B, public C {}; | class D : public B, public C {}; | ||||
// FIXME: Enable this once we support the initialization. | |||||
// This initializes D::B::A::a and not D::C::A::a. | // This initializes D::B::A::a and not D::C::A::a. | ||||
//constexpr D d{12}; | constexpr D d{12}; | ||||
//static_assert(d.B::a == 12); | static_assert(d.B::a == 12); | ||||
//static_assert(d.C::a == 0); | static_assert(d.C::a == 0); | ||||
tbaederAuthorUnsubmitted These lines are added by https://reviews.llvm.org/D143480 now, but the tests are left commented since they require this patch as well. tbaeder: These lines are added by https://reviews.llvm.org/D143480 now, but the tests are left commented… | |||||
}; | }; | ||||
#endif | #endif | ||||
namespace MI { | namespace MI { | ||||
class A { | class A { | ||||
public: | public: | ||||
int a; | int a; | ||||
constexpr A(int a) : a(a) {} | constexpr A(int a) : a(a) {} | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |
We should test that the initialization actually happened.