p1.cpp revision cd8ab51a44e80625d84126780b0d85a7732e25af
1// RUN: %clang_cc1 -std=c++11 -verify -fcxx-exceptions %s 2 3[[noreturn]] void a() { 4 return; // expected-warning {{function 'a' declared 'noreturn' should not return}} 5} 6void a2 [[noreturn]] () { 7 return; // expected-warning {{function 'a2' declared 'noreturn' should not return}} 8} 9 10[[noreturn, noreturn]] void b() { throw 0; } // expected-error {{attribute 'noreturn' cannot appear multiple times in an attribute specifier}} 11[[noreturn]] [[noreturn]] void b2() { throw 0; } // ok 12 13[[noreturn()]] void c(); // expected-error {{attribute 'noreturn' cannot have an argument list}} 14 15void d() [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to types}} 16int d2 [[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions and methods}} 17 18[[noreturn]] int e() { b2(); } // ok 19 20int f(); // expected-note {{declaration missing '[[noreturn]]' attribute is here}} 21[[noreturn]] int f(); // expected-error {{function declared '[[noreturn]]' after its first declaration}} 22int f(); 23 24[[noreturn]] int g(); 25int g() { while (true) b(); } // ok 26[[noreturn]] int g(); 27 28[[gnu::noreturn]] int h(); 29 30template<typename T> void test_type(T) { T::error; } // expected-error {{has no members}} 31template<> void test_type(int (*)()) {} 32 33void check() { 34 // We do not consider [[noreturn]] to be part of the function's type. 35 // However, we do treat [[gnu::noreturn]] as being part of the type. 36 // 37 // This isn't quite GCC-compatible; it treats [[gnu::noreturn]] as 38 // being part of a function *pointer* type, but not being part of 39 // a function type. 40 test_type(e); 41 test_type(f); 42 test_type(g); 43 test_type(h); // expected-note {{instantiation}} 44} 45