1 // RUN: %clang_cc1 -std=c++2a -verify %s 2 3 // p3: if the function is a constructor or destructor, its class shall not have 4 // any virtual base classes; 5 namespace vbase { 6 struct A {}; 7 struct B : virtual A { // expected-note {{virtual}} ~Bvbase::B8 constexpr ~B() {} // expected-error {{constexpr member function not allowed in struct with virtual base class}} 9 }; 10 } 11 12 // p3: its function-body shall not enclose 13 // -- a goto statement 14 // -- an identifier label 15 // -- a variable of non-literal type or of static or thread storage duration 16 namespace contents { 17 struct A { ~Acontents::A18 constexpr ~A() { 19 goto x; // expected-error {{statement not allowed in constexpr function}} 20 x: ; 21 } 22 }; 23 struct B { ~Bcontents::B24 constexpr ~B() { 25 x: ; // expected-error {{statement not allowed in constexpr function}} 26 } 27 }; 28 struct Nonlit { Nonlit(); }; // expected-note {{not literal}} 29 struct C { ~Ccontents::C30 constexpr ~C() { 31 Nonlit nl; // expected-error {{non-literal}} 32 } 33 }; 34 struct D { ~Dcontents::D35 constexpr ~D() { 36 static int a; // expected-error {{static variable}} 37 } 38 }; 39 struct E { ~Econtents::E40 constexpr ~E() { 41 thread_local int e; // expected-error {{thread_local variable}} 42 } 43 }; 44 struct F { ~Fcontents::F45 constexpr ~F() { 46 extern int f; 47 } 48 }; 49 } 50 51 // p5: for every subobject of class type or (possibly multi-dimensional) array 52 // thereof, that class type shall have a constexpr destructor 53 namespace subobject { 54 struct A { 55 ~A(); 56 }; 57 struct B : A { // expected-note {{here}} ~Bsubobject::B58 constexpr ~B() {} // expected-error {{destructor cannot be declared constexpr because base class 'subobject::A' does not have a constexpr destructor}} 59 }; 60 struct C { 61 A a; // expected-note {{here}} ~Csubobject::C62 constexpr ~C() {} // expected-error {{destructor cannot be declared constexpr because data member 'a' does not have a constexpr destructor}} 63 }; 64 struct D : A { 65 A a; 66 constexpr ~D() = delete; 67 }; 68 } 69