1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 // Reachability tests have to come first because they get suppressed
4 // if any errors have occurred.
7 __attribute__((noreturn)) void fail();
13 } // expected-warning {{control reaches end of non-void function}}
20 namespace destructor_tests {
21 __attribute__((noreturn)) void fail();
24 ~A() __attribute__((noreturn)) { fail(); }
28 ~B() __attribute__((noreturn)) { fail(); }
32 struct E : virtual A {};
33 struct F : A, virtual B {};
35 struct H : virtual D {};
38 struct K : virtual A {};
40 struct M : virtual C {};
44 __attribute__((noreturn)) void test_1() { A a; }
45 __attribute__((noreturn)) void test_2() { B b; }
46 __attribute__((noreturn)) void test_3() { C c; }
47 __attribute__((noreturn)) void test_4() { D d; }
48 __attribute__((noreturn)) void test_5() { E e; }
49 __attribute__((noreturn)) void test_6() { F f; }
50 __attribute__((noreturn)) void test_7() { G g; }
51 __attribute__((noreturn)) void test_8() { H h; }
52 __attribute__((noreturn)) void test_9() { I i; }
53 __attribute__((noreturn)) void test_10() { J j; }
54 __attribute__((noreturn)) void test_11() { K k; }
55 __attribute__((noreturn)) void test_12() { L l; }
56 __attribute__((noreturn)) void test_13() { M m; }
57 __attribute__((noreturn)) void test_14() { N n; }
58 __attribute__((noreturn)) void test_15() { O o; }
60 __attribute__((noreturn)) void test_16() { const A& a = A(); }
61 __attribute__((noreturn)) void test_17() { const B& b = B(); }
62 __attribute__((noreturn)) void test_18() { const C& c = C(); }
63 __attribute__((noreturn)) void test_19() { const D& d = D(); }
64 __attribute__((noreturn)) void test_20() { const E& e = E(); }
65 __attribute__((noreturn)) void test_21() { const F& f = F(); }
66 __attribute__((noreturn)) void test_22() { const G& g = G(); }
67 __attribute__((noreturn)) void test_23() { const H& h = H(); }
68 __attribute__((noreturn)) void test_24() { const I& i = I(); }
69 __attribute__((noreturn)) void test_25() { const J& j = J(); }
70 __attribute__((noreturn)) void test_26() { const K& k = K(); }
71 __attribute__((noreturn)) void test_27() { const L& l = L(); }
72 __attribute__((noreturn)) void test_28() { const M& m = M(); }
73 __attribute__((noreturn)) void test_29() { const N& n = N(); }
74 __attribute__((noreturn)) void test_30() { const O& o = O(); }
77 struct BB { BB() {} ~BB() {} };
80 struct EE : virtual AA {};
81 struct FF : AA, virtual BB {};
83 struct HH : virtual DD {};
86 struct KK : virtual AA {};
88 struct MM : virtual CC {};
92 __attribute__((noreturn)) void test_31() {
124 } // expected-warning {{function declared 'noreturn' should not return}}
127 ~P() __attribute__((noreturn)) { fail(); }
131 __attribute__((noreturn)) void test31() {
134 __attribute__((noreturn)) void test32() {
141 __attribute__((noreturn)) void test33() {
145 // FIXME: Code flow analysis does not preserve information about non-null
146 // pointers, so it can't determine that this function is noreturn.
147 __attribute__((noreturn)) void test34() {
150 } // expected-warning {{function declared 'noreturn' should not return}}
156 __attribute__((noreturn)) ~T();
159 // FIXME: Code flow analysis does not preserve information about non-null
160 // pointers or derived class pointers, so it can't determine that this
161 // function is noreturn.
162 __attribute__((noreturn)) void test35() {
165 } // expected-warning {{function declared 'noreturn' should not return}}
169 void f0() __attribute__((__noreturn__));
171 void f2() { f1(f0); }
173 // Taking the address of a noreturn function
176 void (*fp1)() __attribute__((noreturn)) = f0;
179 // Taking the address of an overloaded noreturn function
180 void f0(int) __attribute__((__noreturn__));
184 void (*fp1)() __attribute__((noreturn)) = f0;
187 // No-returned function pointers
188 typedef void (* noreturn_fp)() __attribute__((noreturn));
190 void f3(noreturn_fp); // expected-note{{candidate function}}
194 f3(f2); // expected-error{{no matching function for call}}
199 int blah() __attribute__((noreturn));
203 return 3; // expected-warning {{function 'blah' declared 'noreturn' should not return}}
210 void foo() __attribute__((__noreturn__));
217 void bar() __attribute__((__noreturn__));
224 void baz() __attribute__((__noreturn__));
225 typedef void voidfn();
228 template<typename> void wibble() __attribute__((__noreturn__));
229 template<typename> voidfn wibble;
233 // Overload resolution per over.over should allow implicit noreturn adjustment.
235 __attribute__((noreturn)) void foo(int) {}
236 __attribute__((noreturn)) void foo(double) {}
238 template <typename T>
239 __attribute__((noreturn)) void bar(T) {}
244 template <typename T>
247 // expected-note@+5 {{candidate function template not viable: no overload of 'baz' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}}
248 // expected-note@+4 {{candidate function template not viable: no overload of 'qux' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}}
249 // expected-note@+3 {{candidate function template not viable: no overload of 'bar' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}}
250 // expected-note@+2 {{candidate function template not viable: no overload of 'bar' matching 'void (*)(int)' for 1st argument}}
251 // expected-note@+1 {{candidate function template not viable: no overload of 'bar' matching 'void (*)(int)' for 1st argument}}
252 template <typename T> void accept_T(T) {}
254 // expected-note@+1 {{candidate function not viable: no overload of 'bar' matching 'void (*)(int)' for 1st argument}}
255 void accept_fptr(void (*f)(int)) {
259 // expected-note@+2 {{candidate function not viable: no overload of 'baz' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}}
260 // expected-note@+1 {{candidate function not viable: no overload of 'qux' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}}
261 void accept_noreturn_fptr(void __attribute__((noreturn)) (*f)(int)) {
265 typedef void (*fptr_t)(int);
266 typedef void __attribute__((noreturn)) (*fptr_noreturn_t)(int);
268 // expected-note@+1 {{candidate function not viable: no overload of 'bar' matching 'PR15291::fptr_t' (aka 'void (*)(int)') for 1st argument}}
269 void accept_fptr_t(fptr_t f) {
273 // expected-note@+2 {{candidate function not viable: no overload of 'baz' matching 'PR15291::fptr_noreturn_t' (aka 'void (*)(int) __attribute__((noreturn))') for 1st argument}}
274 // expected-note@+1 {{candidate function not viable: no overload of 'qux' matching 'PR15291::fptr_noreturn_t' (aka 'void (*)(int) __attribute__((noreturn))') for 1st argument}}
275 void accept_fptr_noreturn_t(fptr_noreturn_t f) {
279 // Stripping noreturn should work if everything else is correct.
280 void strip_noreturn() {
282 accept_fptr(bar<int>);
283 accept_fptr(bar<double>); // expected-error {{no matching function for call to 'accept_fptr'}}
286 accept_fptr_t(bar<int>);
287 accept_fptr_t(bar<double>); // expected-error {{no matching function for call to 'accept_fptr_t'}}
289 accept_T<void __attribute__((noreturn)) (*)(int)>(foo);
290 accept_T<void __attribute__((noreturn)) (*)(int)>(bar<int>);
291 accept_T<void __attribute__((noreturn)) (*)(int)>(bar<double>); // expected-error {{no matching function for call to 'accept_T'}}
293 accept_T<void (*)(int)>(foo);
294 accept_T<void (*)(int)>(bar<int>);
295 accept_T<void (*)(int)>(bar<double>); // expected-error {{no matching function for call to 'accept_T'}}
297 accept_T<void (int)>(foo);
298 accept_T<void (int)>(bar<int>);
299 accept_T<void (int)>(bar<double>); // expected-error {{no matching function for call to 'accept_T'}}
302 // Introducing noreturn should not work.
303 void introduce_noreturn() {
304 accept_noreturn_fptr(baz); // expected-error {{no matching function for call to 'accept_noreturn_fptr'}}
305 accept_noreturn_fptr(qux<int>); // expected-error {{no matching function for call to 'accept_noreturn_fptr'}}
307 accept_fptr_noreturn_t(baz); // expected-error {{no matching function for call to 'accept_fptr_noreturn_t'}}
308 accept_fptr_noreturn_t(qux<int>); // expected-error {{no matching function for call to 'accept_fptr_noreturn_t'}}
310 accept_T<void __attribute__((noreturn)) (*)(int)>(baz); // expected-error {{no matching function for call to 'accept_T'}}
311 accept_T<void __attribute__((noreturn)) (*)(int)>(qux<int>); // expected-error {{no matching function for call to 'accept_T'}}