xref: /llvm-project/clang/test/SemaCXX/constexpr-subobj-initialization.cpp (revision 6434dce85df21aabd5669dd9fbe8fa582e40c6ee)
124c91d44STakuya Shimizu // RUN: %clang_cc1 -fsyntax-only -verify %s
2*6434dce8Syronglin // RUN: %clang_cc1 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
324c91d44STakuya Shimizu 
424c91d44STakuya Shimizu namespace baseclass_uninit {
524c91d44STakuya Shimizu struct DelBase {
624c91d44STakuya Shimizu   constexpr DelBase() = delete; // expected-note {{'DelBase' has been explicitly marked deleted here}}
724c91d44STakuya Shimizu };
824c91d44STakuya Shimizu 
9*6434dce8Syronglin struct Foo : DelBase {  // expected-note-re 2{{constructor of base class '{{.*}}DelBase' is not called}}
1024c91d44STakuya Shimizu   constexpr Foo() {}; // expected-error {{call to deleted constructor of 'DelBase'}}
1124c91d44STakuya Shimizu };
1224c91d44STakuya Shimizu constexpr Foo f; // expected-error {{must be initialized by a constant expression}}
1324c91d44STakuya Shimizu struct Bar : Foo {
1424c91d44STakuya Shimizu   constexpr Bar() {};
1524c91d44STakuya Shimizu };
1624c91d44STakuya Shimizu constexpr Bar bar; // expected-error {{must be initialized by a constant expression}}
1724c91d44STakuya Shimizu 
1824c91d44STakuya Shimizu struct Base {};
19*6434dce8Syronglin struct A : Base { // expected-note-re {{constructor of base class '{{.*}}Base' is not called}}
2024c91d44STakuya Shimizu   constexpr A() : value() {} // expected-error {{member initializer 'value' does not name a non-static data member or base class}}
2124c91d44STakuya Shimizu };
2224c91d44STakuya Shimizu 
2324c91d44STakuya Shimizu constexpr A a; // expected-error {{must be initialized by a constant expression}}
2424c91d44STakuya Shimizu 
25*6434dce8Syronglin struct B : Base { // expected-note-re {{constructor of base class '{{.*}}Base' is not called}}
2624c91d44STakuya Shimizu   constexpr B() : {} // expected-error {{expected class member or base class name}}
2724c91d44STakuya Shimizu };
2824c91d44STakuya Shimizu 
2924c91d44STakuya Shimizu constexpr B b; // expected-error {{must be initialized by a constant expression}}
3024c91d44STakuya Shimizu } // namespace baseclass_uninit
3124c91d44STakuya Shimizu 
3224c91d44STakuya Shimizu 
3324c91d44STakuya Shimizu struct Foo {
3424c91d44STakuya Shimizu   constexpr Foo(); // expected-note 2{{declared here}}
3524c91d44STakuya Shimizu };
3624c91d44STakuya Shimizu 
3724c91d44STakuya Shimizu constexpr Foo ff; // expected-error {{must be initialized by a constant expression}} \
3824c91d44STakuya Shimizu                   // expected-note {{undefined constructor 'Foo' cannot be used in a constant expression}}
3924c91d44STakuya Shimizu 
4024c91d44STakuya Shimizu struct Bar : protected Foo {
4124c91d44STakuya Shimizu   int i;
4224c91d44STakuya Shimizu   constexpr Bar() : i(12) {} // expected-note {{undefined constructor 'Foo' cannot be used in a constant expression}}
4324c91d44STakuya Shimizu };
4424c91d44STakuya Shimizu 
4524c91d44STakuya Shimizu constexpr Bar bb; // expected-error {{must be initialized by a constant expression}} \
4624c91d44STakuya Shimizu                   // expected-note {{in call to 'Bar()'}}
4724c91d44STakuya Shimizu 
4824c91d44STakuya Shimizu template <typename Ty>
4924c91d44STakuya Shimizu struct Baz {
5024c91d44STakuya Shimizu   constexpr Baz(); // expected-note {{declared here}}
5124c91d44STakuya Shimizu };
5224c91d44STakuya Shimizu 
5324c91d44STakuya Shimizu struct Quux : Baz<Foo>, private Bar {
5424c91d44STakuya Shimizu   int i;
5524c91d44STakuya Shimizu   constexpr Quux() : i(12) {} // expected-note {{undefined constructor 'Baz' cannot be used in a constant expression}}
5624c91d44STakuya Shimizu };
5724c91d44STakuya Shimizu 
5824c91d44STakuya Shimizu constexpr Quux qx; // expected-error {{must be initialized by a constant expression}} \
5924c91d44STakuya Shimizu                    // expected-note {{in call to 'Quux()'}}
60