[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / AST / ByteCode / constexpr-subobj-initialization.cpp
blob1a359949441906ba6be251ad5cba5eda99c3a90e
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
3 /// This is like the version in test/SemaCXX/, but some of the
4 /// output types and their location has been adapted.
5 /// Differences:
6 /// 1) The type of the uninitialized base class is printed WITH the namespace,
7 /// i.e. 'baseclass_uninit::DelBase' instead of just 'DelBase'.
10 namespace baseclass_uninit {
11 struct DelBase {
12 constexpr DelBase() = delete; // expected-note {{'DelBase' has been explicitly marked deleted here}}
15 struct Foo : DelBase { // expected-note 2{{constructor of base class 'baseclass_uninit::DelBase' is not called}}
16 constexpr Foo() {}; // expected-error {{call to deleted constructor of 'DelBase'}}
18 constexpr Foo f; // expected-error {{must be initialized by a constant expression}}
20 struct Bar : Foo {
21 constexpr Bar() {};
23 constexpr Bar bar; // expected-error {{must be initialized by a constant expression}}
25 struct Base {};
26 struct A : Base { // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}}
27 constexpr A() : value() {} // expected-error {{member initializer 'value' does not name a non-static data member or base class}}
30 constexpr A a; // expected-error {{must be initialized by a constant expression}}
33 struct B : Base { // expected-note {{constructor of base class 'baseclass_uninit::Base' is not called}}
34 constexpr B() : {} // expected-error {{expected class member or base class name}}
37 constexpr B b; // expected-error {{must be initialized by a constant expression}}
38 } // namespace baseclass_uninit
41 struct Foo {
42 constexpr Foo(); // expected-note 2{{declared here}}
45 constexpr Foo ff; // expected-error {{must be initialized by a constant expression}} \
46 // expected-note {{undefined constructor 'Foo' cannot be used in a constant expression}}
48 struct Bar : protected Foo {
49 int i;
50 constexpr Bar() : i(12) {} // expected-note {{undefined constructor 'Foo' cannot be used in a constant expression}}
53 constexpr Bar bb; // expected-error {{must be initialized by a constant expression}} \
54 // expected-note {{in call to 'Bar()'}}
56 template <typename Ty>
57 struct Baz {
58 constexpr Baz(); // expected-note {{declared here}}
61 struct Quux : Baz<Foo>, private Bar {
62 int i;
63 constexpr Quux() : i(12) {} // expected-note {{undefined constructor 'Baz' cannot be used in a constant expression}}
66 constexpr Quux qx; // expected-error {{must be initialized by a constant expression}} \
67 // expected-note {{in call to 'Quux()'}}