Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/test/AST/Interp/cxx20.cpp
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | constexpr ctor_test<false> bad_ctor; // expected-error {{must be initialized by a constant expression}} \ | ||||
// ref-error {{must be initialized by a constant expression}} \ | // ref-error {{must be initialized by a constant expression}} \ | ||||
// ref-note {{in call to}} | // ref-note {{in call to}} | ||||
constexpr dtor_test<false> bad_dtor; // expected-error {{must have constant destruction}} \ | constexpr dtor_test<false> bad_dtor; // expected-error {{must have constant destruction}} \ | ||||
// expected-note {{in call to}} \ | // expected-note {{in call to}} \ | ||||
// ref-error {{must have constant destruction}} \ | // ref-error {{must have constant destruction}} \ | ||||
// ref-note {{in call to}} | // ref-note {{in call to}} | ||||
}; | }; | ||||
namespace BaseInit { | |||||
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, ""); // expected-error {{not an integral constant expression}} \ | |||||
// expected-note {{read of object outside its lifetime}} \ | |||||
// ref-error {{not an integral constant expression}} \ | |||||
// ref-note {{read of uninitialized object}} | |||||
struct Mixin { | |||||
int b; | |||||
constexpr Mixin() = default; | |||||
constexpr Mixin(int b) : b(b) {} | |||||
}; | |||||
struct Final2 : Base, Mixin { | |||||
int c; | |||||
constexpr Final2(int a, int b, int c) : Mixin(b), c(c) {} | |||||
constexpr Final2(int a, int b, int c, bool) : c(c) {} | |||||
}; | |||||
static_assert(Final2{1, 2, 3}.c == 3, ""); // OK | |||||
static_assert(Final2{1, 2, 3}.b == 2, ""); // OK | |||||
static_assert(Final2{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \ | |||||
// expected-note {{read of object outside its lifetime}} \ | |||||
// ref-error {{not an integral constant expression}} \ | |||||
// ref-note {{read of uninitialized object}} | |||||
struct Mixin3 { | |||||
int b; | |||||
}; | |||||
struct Final3 : Base, Mixin3 { | |||||
int c; | |||||
constexpr Final3(int a, int b, int c) : c(c) { this->b = b; } | |||||
constexpr Final3(int a, int b, int c, bool) : c(c) {} | |||||
}; | |||||
static_assert(Final3{1, 2, 3}.c == 3, ""); // OK | |||||
static_assert(Final3{1, 2, 3}.b == 2, ""); // OK | |||||
static_assert(Final3{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \ | |||||
// expected-note {{read of object outside its lifetime}} \ | |||||
// ref-error {{not an integral constant expression}} \ | |||||
// ref-note {{read of uninitialized object}} | |||||
}; | |||||
namespace Destructors { | namespace Destructors { | ||||
class Inc final { | class Inc final { | ||||
public: | public: | ||||
int &I; | int &I; | ||||
constexpr Inc(int &I) : I(I) {} | constexpr Inc(int &I) : I(I) {} | ||||
constexpr ~Inc() { | constexpr ~Inc() { | ||||
I++; | I++; | ||||
▲ Show 20 Lines • Show All 238 Lines • Show Last 20 Lines |