diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp | 44 | ||||
-rw-r--r-- | clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp | 3 | ||||
-rw-r--r-- | clang/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp | 5 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/cxx11-noreturn.cpp | 8 | ||||
-rw-r--r-- | clang/test/Parser/cxx0x-attributes.cpp | 7 | ||||
-rw-r--r-- | clang/test/Parser/objcxx11-attributes.mm | 6 |
6 files changed, 65 insertions, 8 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp new file mode 100644 index 00000000000..0af241f55fe --- /dev/null +++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -std=c++11 -verify -fcxx-exceptions %s + +[[noreturn]] void a() { + return; // expected-warning {{function 'a' declared 'noreturn' should not return}} +} +void a2 [[noreturn]] () { + return; // expected-warning {{function 'a2' declared 'noreturn' should not return}} +} + +[[noreturn, noreturn]] void b() { throw 0; } // expected-error {{attribute 'noreturn' cannot appear multiple times in an attribute specifier}} +[[noreturn]] [[noreturn]] void b2() { throw 0; } // ok + +[[noreturn()]] void c(); // expected-error {{attribute 'noreturn' cannot have an argument list}} + +void d() [[noreturn]]; // expected-error {{'noreturn' attribute cannot be applied to types}} +int d2 [[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions and methods}} + +[[noreturn]] int e() { b2(); } // ok + +int f(); // expected-note {{declaration missing '[[noreturn]]' attribute is here}} +[[noreturn]] int f(); // expected-error {{function declared '[[noreturn]]' after its first declaration}} +int f(); + +[[noreturn]] int g(); +int g() { while (true) b(); } // ok +[[noreturn]] int g(); + +[[gnu::noreturn]] int h(); + +template<typename T> void test_type(T) { T::error; } // expected-error {{has no members}} +template<> void test_type(int (*)()) {} + +void check() { + // We do not consider [[noreturn]] to be part of the function's type. + // However, we do treat [[gnu::noreturn]] as being part of the type. + // + // This isn't quite GCC-compatible; it treats [[gnu::noreturn]] as + // being part of a function *pointer* type, but not being part of + // a function type. + test_type(e); + test_type(f); + test_type(g); + test_type(h); // expected-note {{instantiation}} +} diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp index 68460f0354b..9dffc1ff264 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p5.cpp @@ -5,7 +5,8 @@ void test_attributes() { auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{control may reach end of non-void lambda}} - auto nrl2 = []() [[noreturn]] { return; }; // expected-error{{lambda declared 'noreturn' should not return}} + // FIXME: GCC accepts the [[gnu::noreturn]] attribute here. + auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'noreturn' ignored}} } template<typename T> diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp index 49b9c66b1ce..407b083231a 100644 --- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp @@ -2,10 +2,11 @@ template<typename T> void test_attributes() { - auto nrl = []() [[noreturn]] {}; // expected-error{{lambda declared 'noreturn' should not return}} + // FIXME: GCC accepts [[gnu::noreturn]] here. + auto nrl = []() [[gnu::noreturn]] {}; // expected-warning{{attribute 'noreturn' ignored}} } -template void test_attributes<int>(); // expected-note{{in instantiation of function}} +template void test_attributes<int>(); template<typename T> void call_with_zero() { diff --git a/clang/test/CodeGenCXX/cxx11-noreturn.cpp b/clang/test/CodeGenCXX/cxx11-noreturn.cpp new file mode 100644 index 00000000000..ee513120f9a --- /dev/null +++ b/clang/test/CodeGenCXX/cxx11-noreturn.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -emit-llvm -std=c++11 %s -o - | FileCheck %s + +int g(); + +// CHECK: _Z1fv(){{.*}} noreturn +[[noreturn]] int f() { + while (g()) {} +} diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index dac159a03f4..ab6aa70c28b 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -210,8 +210,11 @@ template<typename...Ts> void variadic() { // Expression tests void bar () { - [] () [[noreturn]] { return; } (); // expected-error {{should not return}} - [] () [[noreturn]] { throw; } (); + // FIXME: GCC accepts [[gnu::noreturn]] on a lambda, even though it appertains + // to the operator()'s type, and GCC does not otherwise accept attributes + // applied to types. Use that to test this. + [] () [[gnu::noreturn]] { return; } (); // expected-warning {{attribute 'noreturn' ignored}} FIXME-error {{should not return}} + [] () [[gnu::noreturn]] { throw; } (); // expected-warning {{attribute 'noreturn' ignored}} new int[42][[]][5][[]]{}; } diff --git a/clang/test/Parser/objcxx11-attributes.mm b/clang/test/Parser/objcxx11-attributes.mm index 9ad85d310f9..c72f26d1012 100644 --- a/clang/test/Parser/objcxx11-attributes.mm +++ b/clang/test/Parser/objcxx11-attributes.mm @@ -13,12 +13,12 @@ void f(X *noreturn) { int a[ [noreturn getSize] ]; // ... but is interpreted as an attribute where possible. - int b[ [noreturn] ]; // expected-warning {{'noreturn' only applies to function types}} + int b[ [noreturn] ]; // expected-error {{'noreturn' attribute only applies to functions and methods}} int c[ [noreturn getSize] + 1 ]; // An array size which is computed by a lambda is not OK. - int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-warning {{'noreturn' only applies}} + int d[ [noreturn] { return 3; } () ]; // expected-error {{expected ']'}} expected-error {{'noreturn' attribute only applies}} // A message send which contains a message send is OK. [ [ X alloc ] init ]; @@ -40,7 +40,7 @@ void f(X *noreturn) { expected-warning {{unknown attribute 'bitand' ignored}} // FIXME: Suppress vexing parse warning - [[noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} + [[gnu::noreturn]]int(e)(); // expected-warning {{function declaration}} expected-note {{replace parentheses with an initializer}} int e2(); // expected-warning {{interpreted as a function declaration}} expected-note{{}} // A function taking a noreturn function. |