brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 18fa9cf Raw
64 lines · cpp
1// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify2// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter3 4struct A {5  constexpr A() : a(b + 1), b(a + 1) {} // expected-note 5{{outside its lifetime}}6  int a;7  int b;8};9struct B { // expected-note {{in call to 'A()'}}10  A a;11};12 13constexpr A a1; // expected-error {{constant expression}} expected-note {{in call to 'A()'}}14constexpr A a2 = A(); // expected-error {{constant expression}} expected-note {{in call to 'A()'}}15void f() {16  constexpr A a; // expected-error {{constant expression}} expected-note {{in call to 'A()'}}17}18 19constexpr B b1; // expected-error {{constant expression}} expected-note {{in call to 'B()'}}20constexpr B b2 = B(); // ok21static_assert(b2.a.a == 1, "");22static_assert(b2.a.b == 2, "");23 24struct C {25  int c;26};27struct D : C { int d; };28constexpr C c1; // expected-error {{without a user-provided default constructor}}29constexpr C c2 = C(); // ok30constexpr D d1; // expected-error {{without a user-provided default constructor}}31constexpr D d2 = D(); // ok with DR145232static_assert(D().c == 0, "");33static_assert(D().d == 0, "");34 35struct V : virtual C {};36template<typename T> struct Z : T {37  constexpr Z() : V() {}38};39constexpr int n = Z<V>().c; // expected-error {{constant expression}} expected-note {{non-literal type 'Z<V>'}}40 41struct E { // expected-note {{in call to 'A()'}}42  A a[2];43};44constexpr E e1; // expected-error {{constant expression}} expected-note {{in call to 'E()'}}45constexpr E e2 = E();46static_assert(e2.a[0].a == 1, "");47static_assert(e2.a[0].b == 2, "");48static_assert(e2.a[1].a == 1, "");49static_assert(e2.a[1].b == 2, "");50 51namespace InvalidDeclInsideConstExpr {52template <int a> struct i; // expected-note {{template is declared here}}53template <> struct i<0> {};54 55template <int x> constexpr auto c() {56  // i<x> is valid, but it might be incomplete. g would be invalid in that case.57  i<x> g; // expected-error {{implicit instantiation of undefined template 'InvalidDeclInsideConstExpr::i<1>'}}58  return 0;59}60 61auto y = c<1>(); // expected-note {{in instantiation of function template specialization 'InvalidDeclInsideConstExpr::c<1>' requested here}}62auto x = c<0>(); // this is valid.63}64