1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 243c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 31de85338543dd6228eb518185e385d94d377f4cbJohn McCall// Reachability tests have to come first because they get suppressed 41de85338543dd6228eb518185e385d94d377f4cbJohn McCall// if any errors have occurred. 51de85338543dd6228eb518185e385d94d377f4cbJohn McCallnamespace test5 { 61de85338543dd6228eb518185e385d94d377f4cbJohn McCall struct A { 71de85338543dd6228eb518185e385d94d377f4cbJohn McCall __attribute__((noreturn)) void fail(); 81de85338543dd6228eb518185e385d94d377f4cbJohn McCall void nofail(); 91de85338543dd6228eb518185e385d94d377f4cbJohn McCall } a; 101de85338543dd6228eb518185e385d94d377f4cbJohn McCall 111de85338543dd6228eb518185e385d94d377f4cbJohn McCall int &test1() { 121de85338543dd6228eb518185e385d94d377f4cbJohn McCall a.nofail(); 131de85338543dd6228eb518185e385d94d377f4cbJohn McCall } // expected-warning {{control reaches end of non-void function}} 141de85338543dd6228eb518185e385d94d377f4cbJohn McCall 151de85338543dd6228eb518185e385d94d377f4cbJohn McCall int &test2() { 161de85338543dd6228eb518185e385d94d377f4cbJohn McCall a.fail(); 171de85338543dd6228eb518185e385d94d377f4cbJohn McCall } 181de85338543dd6228eb518185e385d94d377f4cbJohn McCall} 191de85338543dd6228eb518185e385d94d377f4cbJohn McCall 2043c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor// PR5620 2143c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid f0() __attribute__((__noreturn__)); 2243c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid f1(void (*)()); 2343c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid f2() { f1(f0); } 2443c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 2543c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor// Taking the address of a noreturn function 2643c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid test_f0a() { 2743c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor void (*fp)() = f0; 2843c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor void (*fp1)() __attribute__((noreturn)) = f0; 2943c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor} 3043c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 3143c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor// Taking the address of an overloaded noreturn function 3243c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid f0(int) __attribute__((__noreturn__)); 3343c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 3443c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid test_f0b() { 3543c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor void (*fp)() = f0; 3643c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor void (*fp1)() __attribute__((noreturn)) = f0; 3743c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor} 3843c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 3943c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor// No-returned function pointers 4043c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregortypedef void (* noreturn_fp)() __attribute__((noreturn)); 4143c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 4243c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid f3(noreturn_fp); // expected-note{{candidate function}} 4343c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor 4443c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregorvoid test_f3() { 4543c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor f3(f0); // okay 4643c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor f3(f2); // expected-error{{no matching function for call}} 4743c79c2b07abc7ba6d9f243b84ee6539de4d2652Douglas Gregor} 48f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopes 49f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopes 50f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopesclass xpto { 515d1d7ae120c2c8e6cba5d2a712b33500a5aecc10Anders Carlsson int blah() __attribute__((noreturn)); 52f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopes}; 53f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopes 54f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopesint xpto::blah() { 55f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopes return 3; // expected-warning {{function 'blah' declared 'noreturn' should not return}} 56f75b8309e3e40290683e3d34bac3a04e88d9c625Nuno Lopes} 5771074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 5871074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor// PR12948 5971074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 6071074fdf40a8f5b53810712102b58c27efc30759Douglas Gregornamespace PR12948 { 6171074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor template<int> 6271074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor void foo() __attribute__((__noreturn__)); 6371074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 6471074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor template<int> 6571074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor void foo() { 6671074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor while (1) continue; 6771074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor } 6871074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 6971074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor void bar() __attribute__((__noreturn__)); 7071074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 7171074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor void bar() { 7271074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor foo<0>(); 7371074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor } 7471074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 7571074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 7671074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor void baz() __attribute__((__noreturn__)); 7771074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor typedef void voidfn(); 7871074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor voidfn baz; 7971074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor 8071074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor template<typename> void wibble() __attribute__((__noreturn__)); 8171074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor template<typename> voidfn wibble; 8271074fdf40a8f5b53810712102b58c27efc30759Douglas Gregor} 83092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 84092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor// PR15291 85092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor// Overload resolution per over.over should allow implicit noreturn adjustment. 86092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregornamespace PR15291 { 87092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor __attribute__((noreturn)) void foo(int) {} 88092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor __attribute__((noreturn)) void foo(double) {} 89092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 90092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor template <typename T> 91092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor __attribute__((noreturn)) void bar(T) {} 92092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 93092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void baz(int) {} 94092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void baz(double) {} 95092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 96092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor template <typename T> 97092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void qux(T) {} 98092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 99092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+5 {{candidate function [with T = void (*)(int) __attribute__((noreturn))] not viable: no overload of 'baz' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}} 100092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+4 {{candidate function [with T = void (*)(int) __attribute__((noreturn))] not viable: no overload of 'qux' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}} 101092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+3 {{candidate function [with T = void (*)(int) __attribute__((noreturn))] not viable: no overload of 'bar' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}} 102092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+2 {{candidate function [with T = void (*)(int)] not viable: no overload of 'bar' matching 'void (*)(int)' for 1st argument}} 103092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+1 {{candidate function [with T = void (int)] not viable: no overload of 'bar' matching 'void (*)(int)' for 1st argument}} 104092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor template <typename T> void accept_T(T) {} 105092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 106092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+1 {{candidate function not viable: no overload of 'bar' matching 'void (*)(int)' for 1st argument}} 107092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void accept_fptr(void (*f)(int)) { 108092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor f(42); 109092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor } 110092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 111092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+2 {{candidate function not viable: no overload of 'baz' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}} 112092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+1 {{candidate function not viable: no overload of 'qux' matching 'void (*)(int) __attribute__((noreturn))' for 1st argument}} 113092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void accept_noreturn_fptr(void __attribute__((noreturn)) (*f)(int)) { 114092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor f(42); 115092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor } 116092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 117092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor typedef void (*fptr_t)(int); 118092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor typedef void __attribute__((noreturn)) (*fptr_noreturn_t)(int); 119092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 120092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+1 {{candidate function not viable: no overload of 'bar' matching 'fptr_t' (aka 'void (*)(int)') for 1st argument}} 121092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void accept_fptr_t(fptr_t f) { 122092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor f(42); 123092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor } 124092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 125092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+2 {{candidate function not viable: no overload of 'baz' matching 'fptr_noreturn_t' (aka 'void (*)(int) __attribute__((noreturn))') for 1st argument}} 126092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // expected-note@+1 {{candidate function not viable: no overload of 'qux' matching 'fptr_noreturn_t' (aka 'void (*)(int) __attribute__((noreturn))') for 1st argument}} 127092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void accept_fptr_noreturn_t(fptr_noreturn_t f) { 128092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor f(42); 129092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor } 130092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 131092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // Stripping noreturn should work if everything else is correct. 132092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void strip_noreturn() { 133092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr(foo); 134092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr(bar<int>); 135092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr(bar<double>); // expected-error {{no matching function for call to 'accept_fptr'}} 136092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 137092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr_t(foo); 138092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr_t(bar<int>); 139092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr_t(bar<double>); // expected-error {{no matching function for call to 'accept_fptr_t'}} 140092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 141092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void __attribute__((noreturn)) (*)(int)>(foo); 142092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void __attribute__((noreturn)) (*)(int)>(bar<int>); 143092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void __attribute__((noreturn)) (*)(int)>(bar<double>); // expected-error {{no matching function for call to 'accept_T'}} 144092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 145092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void (*)(int)>(foo); 146092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void (*)(int)>(bar<int>); 147092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void (*)(int)>(bar<double>); // expected-error {{no matching function for call to 'accept_T'}} 148092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 149092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void (int)>(foo); 150092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void (int)>(bar<int>); 151092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void (int)>(bar<double>); // expected-error {{no matching function for call to 'accept_T'}} 152092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor } 153092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 154092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor // Introducing noreturn should not work. 155092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor void introduce_noreturn() { 156092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_noreturn_fptr(baz); // expected-error {{no matching function for call to 'accept_noreturn_fptr'}} 157092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_noreturn_fptr(qux<int>); // expected-error {{no matching function for call to 'accept_noreturn_fptr'}} 158092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 159092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr_noreturn_t(baz); // expected-error {{no matching function for call to 'accept_fptr_noreturn_t'}} 160092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_fptr_noreturn_t(qux<int>); // expected-error {{no matching function for call to 'accept_fptr_noreturn_t'}} 161092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor 162092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void __attribute__((noreturn)) (*)(int)>(baz); // expected-error {{no matching function for call to 'accept_T'}} 163092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor accept_T<void __attribute__((noreturn)) (*)(int)>(qux<int>); // expected-error {{no matching function for call to 'accept_T'}} 164092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor } 165092140a434366007a611c0a1a73fb6a4e8ff7f5eDouglas Gregor} 166