1 // RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -fcxx-exceptions -verify 2 3 // verify no value-dependent-assertion crash in constexpr function body and no 4 // bogus diagnostics. 5 class Foo { 6 constexpr Foo() { 7 while (invalid()) {} // expected-error {{use of undeclared identifier}} 8 if (invalid()) {} // expected-error {{use of undeclared identifier}} 9 } 10 }; 11 12 constexpr void test1() { 13 while (invalid()) {} // expected-error {{use of undeclared identifier}} 14 if (invalid()) {} // expected-error {{use of undeclared identifier}} 15 } 16 17 struct A { 18 int *p = new int(invalid()); // expected-error {{use of undeclared identifier}} 19 constexpr ~A() { delete p; } 20 }; 21 constexpr int test2() { 22 A a; 23 return 1; 24 } 25 26 constexpr int test3() { 27 return invalid(); // expected-error {{use of undeclared identifier}} 28 } 29 30 constexpr int test4() { 31 if (invalid()) // expected-error {{use of undeclared identifier}} 32 return 1; 33 else 34 return 0; 35 } 36 37 constexpr int test5() { // expected-error {{constexpr function never produce}} 38 for (;; a++); // expected-error {{use of undeclared identifier}} \ 39 expected-note {{constexpr evaluation hit maximum step limit; possible infinite loop?}} 40 return 1; 41 } 42 43 constexpr int test6() { // expected-error {{constexpr function never produce}} 44 int n = 0; 45 switch (n) { 46 for (;; a++) { // expected-error {{use of undeclared identifier}} 47 case 0:; // expected-note {{constexpr evaluation hit maximum step limit; possible infinite loop?}} 48 } 49 } 50 return 0; 51 } 52 53 constexpr bool test7() { 54 for (int n = 0; ; invalid()) { if (n == 1) return true; } // expected-error {{use of undeclared identifier}} 55 throw "bad"; 56 } 57 58 constexpr void test8() { 59 do {} while (invalid()); // expected-error {{use of undeclared identifier}} 60 throw "bad"; 61 } 62 63 template<int x> constexpr int f(int y) { // expected-note {{candidate template ignored}} 64 return x * y; 65 } 66 constexpr int test9(int x) { 67 return f<1>(f<x>(1)); // expected-error {{no matching function for call to 'f'}} 68 } 69 70 constexpr int test10() { return undef(); } // expected-error {{use of undeclared identifier 'undef'}} 71 static_assert(test10() <= 1, "should not crash"); // expected-error {{static_assert expression is not an integral constant expression}} 72 73 struct X {} array[] = {undef()}; // expected-error {{use of undeclared identifier 'undef'}} 74 constexpr void test11() { 75 for (X& e : array) {} 76 } 77