1 // RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify 2 3 namespace test0 { 4 struct Indestructible { 5 // Indestructible(); 6 ~Indestructible() = delete; // expected-note 2{{deleted}} 7 }; 8 Indestructible make_indestructible(); 9 10 void test() { 11 // no crash. 12 int s = sizeof(make_indestructible()); // expected-error {{deleted}} 13 constexpr int ss = sizeof(make_indestructible()); // expected-error {{deleted}} 14 static_assert(ss, ""); 15 int array[ss]; 16 } 17 } 18 19 namespace test1 { 20 constexpr int foo() { return 1; } // expected-note {{candidate function not viable}} 21 // verify the "not an integral constant expression" diagnostic is suppressed. 22 static_assert(1 == foo(1), ""); // expected-error {{no matching function}} 23 } 24 25 namespace test2 { 26 void foo(); // expected-note 3{{requires 0 arguments}} 27 void func() { 28 // verify that "field has incomplete type" diagnostic is suppressed. 29 typeof(foo(42)) var; // expected-error {{no matching function}} \ 30 31 // FIXME: suppress the "cannot initialize a variable" diagnostic. 32 int a = foo(1); // expected-error {{no matching function}} \ 33 // expected-error {{cannot initialize a variable of type}} 34 35 // FIXME: suppress the "invalid application" diagnostic. 36 int s = sizeof(foo(42)); // expected-error {{no matching function}} \ 37 // expected-error {{invalid application of 'sizeof'}} 38 }; 39 } 40 41 namespace test3 { 42 template <int N> 43 constexpr int templated() __attribute__((enable_if(N, ""))) { // expected-note {{candidate disabled}} 44 return 1; 45 } 46 // verify that "constexpr variable must be initialized" diagnostic is suppressed. 47 constexpr int A = templated<0>(); // expected-error{{no matching function}} 48 49 template <typename T> 50 struct AA { 51 template <typename U> 52 static constexpr int getB() { // expected-note{{candidate template ignored}} 53 return 2; 54 } 55 static constexpr int foo2() { 56 return AA<T>::getB(); // expected-error{{no matching function for call to 'getB'}} 57 } 58 }; 59 // FIXME: should we suppress the "be initialized by a constant expression" diagnostic? 60 constexpr auto x2 = AA<int>::foo2(); // expected-error {{be initialized by a constant expression}} \ 61 // expected-note {{in instantiation of member function}} 62 } 63 64 // verify no assertion failure on violating value category. 65 namespace test4 { 66 int &&f(int); // expected-note {{candidate function not viable}} 67 int &&k = f(); // expected-error {{no matching function for call}} 68 } 69 70 // verify that "type 'double' cannot bind to a value of unrelated type 'int'" diagnostic is suppressed. 71 namespace test5 { 72 template<typename T> using U = T; // expected-note {{template parameter is declared here}} 73 template<typename...Ts> U<Ts...>& f(); // expected-error {{pack expansion used as argument for non-pack parameter of alias template}} 74 double &s1 = f(); // expected-error {{no matching function}} 75 } 76 77 namespace test6 { 78 struct T { 79 T() = delete; // expected-note {{has been explicitly marked deleted here}} 80 }; 81 82 void func() { 83 // verify that no -Wunused-value diagnostic. 84 (T(T())); // expected-error {{call to deleted constructor}} 85 } 86 } 87 88 // verify the secondary diagnostic "no matching function" is emitted. 89 namespace test7 { 90 struct C { 91 C() = delete; // expected-note {{has been explicitly marked deleted}} 92 }; 93 void f(C &); // expected-note {{candidate function not viable: expects an lvalue for 1st argument}} 94 void test() { 95 f(C()); // expected-error {{call to deleted constructor}} \ 96 expected-error {{no matching function for call}} 97 } 98 } 99 100 // verify the secondary diagnostic "cannot initialize" is emitted. 101 namespace test8 { 102 typedef int arr[]; 103 int v = arr(); // expected-error {{array types cannot be value-initialized}} \ 104 expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'test8::arr'}} 105 } 106 107 namespace test9 { 108 auto f(); // expected-note {{candidate function not viable}} 109 // verify no crash on evaluating the size of undeduced auto type. 110 static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for call to 'f'}} 111 } 112 113 namespace test10 { 114 // Ensure we don't assert here. 115 int f(); // expected-note {{candidate}} 116 template<typename T> const int k = f(T()); // expected-error {{no matching function}} 117 static_assert(k<int> == 1, ""); // expected-note {{instantiation of}} 118 } 119 120 namespace test11 { 121 // Verify we do not assert()-fail here. 122 template <class T> void foo(T &t); 123 template <typename T> 124 void bar(T t) { 125 foo(t); 126 } 127 128 template <typename T = void *> 129 struct S { // expected-note {{candidate}} 130 S(T t); // expected-note {{candidate}} 131 ~S(); 132 }; 133 template <typename T> S(T t) -> S<void *>; 134 135 void baz() { 136 bar(S(123)); // expected-error {{no matching conversion for functional-style cast from 'int' to 'S<void *>'}} 137 } 138 } // namespace test11 139 140 namespace test12 { 141 // Verify we do not crash. 142 int fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}} 143 void crash1() { fun(); } 144 void crash2() { constexpr int s = fun(); } 145 } // namespace test12 146 147 namespace test13 { 148 enum Circular { // expected-note {{not complete until the closing '}'}} 149 Circular_A = Circular(1), // expected-error {{'test13::Circular' is an incomplete type}} 150 }; 151 // Enumerators can be evaluated (they evaluate as zero, but we don't care). 152 static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static_assert failed}} 153 } 154 155 namespace test14 { 156 extern "C" void *memset(void *, int b, unsigned long) { 157 int * const c(undef()); // expected-error {{undeclared identifier}} 158 // Verify we do not crash on evaluating *c whose initializer is a NULL-type ParenListExpr! 159 memset(c, 0, *c); // crash1 160 161 b = __builtin_object_size(c, 0); // crash2 162 } 163 } 164