1 // RUN: %clang_cc1 %s -fcxx-exceptions -fdeclspec -fsyntax-only -Wexceptions -verify -std=c++14
2 // RUN: %clang_cc1 %s -fcxx-exceptions -fdeclspec -fsyntax-only -Wexceptions -verify -std=c++17 -DCPP17
4 __attribute__((nothrow
)) void f1();
5 static_assert(noexcept(f1()), "");
7 // expected-error@+2 {{exception specification in declaration does not match previous declaration}}
8 // expected-note@-2 {{previous declaration is here}}
9 void f1() noexcept(false);
11 __attribute__((nothrow
)) void f2();
12 static_assert(noexcept(f2()), "");
13 // expected-error@+2 {{exception specification in declaration does not match previous declaration}}
14 // expected-note@-3 {{previous declaration is here}}
15 void f2() noexcept(false);
17 void f3() __attribute__((nothrow
));
18 static_assert(noexcept(f3()), "");
20 // expected-error@+2 {{exception specification in declaration does not match previous declaration}}
21 // expected-note@-2 {{previous declaration is here}}
22 void f3() noexcept(false);
24 // Still noexcept due to throw()
25 __attribute__((nothrow
)) void f4() throw();
26 static_assert(noexcept(f4()), "");
28 // Still noexcept due to noexcept
29 __attribute__((nothrow
)) void f5() noexcept
;
30 static_assert(noexcept(f5()), "");
32 // Still noexcept due to noexcept(true)
33 __attribute__((nothrow
)) void f6() noexcept(true);
34 static_assert(noexcept(f6()), "");
37 // Doesn't override C++ implementation.
38 // expected-warning@+1{{'nothrow' attribute conflicts with exception specification; attribute ignored}}
39 __attribute__((nothrow
)) void f7() throw(int);
40 static_assert(!noexcept(f7()), "");
43 // Doesn't override C++ implementation.
44 // expected-warning@+1{{'nothrow' attribute conflicts with exception specification; attribute ignored}}
45 __attribute__((nothrow
)) void f8() noexcept(false);
46 static_assert(!noexcept(f8()), "");
48 __declspec(nothrow
) void foo1() noexcept
;
49 __declspec(nothrow
) void foo2() noexcept(true);
50 // expected-warning@+1{{'nothrow' attribute conflicts with exception specification; attribute ignored}}
51 __declspec(nothrow
) void foo3() noexcept(false);
52 __declspec(nothrow
) void foo4() noexcept(noexcept(foo1()));
53 __declspec(nothrow
) void foo5() noexcept(noexcept(foo2()));
54 // expected-warning@+1{{'nothrow' attribute conflicts with exception specification; attribute ignored}}
55 __declspec(nothrow
) void foo6() noexcept(noexcept(foo3()));
58 __declspec(nothrow
) void foo7() noexcept(noexcept(F()));
60 // FIXME: It would be nice to be able to warn on these, however at the time we
61 // evaluate the nothrow, these have yet to be parsed, so the data is not yet
64 __declspec(nothrow
) void f1();
66 __declspec(nothrow
) void f2() throw();
67 __declspec(nothrow
) void f3() throw(int);
69 __declspec(nothrow
) void f4() noexcept(true);
70 __declspec(nothrow
) void f5() noexcept(false);
76 // expected-note@+1{{overridden virtual function is here}}
77 virtual __declspec(nothrow
) void foo() = 0;
78 // expected-note@+1{{previous declaration is here}}
79 __declspec(nothrow
) void bar();
82 // expected-warning@+1{{'bar' is missing exception specification '__attribute__((nothrow))'}}
85 class Sub
: public Base
{
87 // expected-warning@+1{{exception specification of overriding function is more lax than base version}}
92 namespace FuncPointerReferenceConverts
{
96 // expected-error@+6{{target exception specification is not superset of source}}
97 // expected-error@+6{{target exception specification is not superset of source}}
99 // expected-error@+3{{non-const lvalue reference to type 'void () __attribute__((nothrow))' cannot bind to a value of unrelated type 'void ()'}}
100 // expected-error@+3{{cannot initialize a variable of type 'void (*)() __attribute__((nothrow))' with an lvalue of type 'void ()': different exception specifications}}
102 __declspec(nothrow
) void (&FuncRef
)() = FuncToBeRefed
;
103 __declspec(nothrow
) void (*FuncPtr
)() = FuncToBeRefed
;