| 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 |
| 3 |
|
| 4 |
__attribute__((nothrow)) void f1(); |
| 5 |
static_assert(noexcept(f1()), ""); |
| 6 |
void f1() noexcept; |
| 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); |
| 10 |
|
| 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); |
| 16 |
|
| 17 |
void f3() __attribute__((nothrow)); |
| 18 |
static_assert(noexcept(f3()), ""); |
| 19 |
void f3() noexcept; |
| 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); |
| 23 |
|
| 24 |
// Still noexcept due to throw() |
| 25 |
__attribute__((nothrow)) void f4() throw(); |
| 26 |
static_assert(noexcept(f4()), ""); |
| 27 |
|
| 28 |
// Still noexcept due to noexcept |
| 29 |
__attribute__((nothrow)) void f5() noexcept; |
| 30 |
static_assert(noexcept(f5()), ""); |
| 31 |
|
| 32 |
// Still noexcept due to noexcept(true) |
| 33 |
__attribute__((nothrow)) void f6() noexcept(true); |
| 34 |
static_assert(noexcept(f6()), ""); |
| 35 |
|
| 36 |
#ifndef CPP17 |
| 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()), ""); |
| 41 |
#endif |
| 42 |
|
| 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()), ""); |
| 47 |
|
| 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())); |
| 56 |
|
| 57 |
template<typename F> |
| 58 |
__declspec(nothrow) void foo7() noexcept(noexcept(F())); |
| 59 |
|
| 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 |
| 62 |
// there. |
| 63 |
struct S { |
| 64 |
__declspec(nothrow) void f1(); |
| 65 |
#ifndef CPP17 |
| 66 |
__declspec(nothrow) void f2() throw(); |
| 67 |
__declspec(nothrow) void f3() throw(int); |
| 68 |
#endif |
| 69 |
__declspec(nothrow) void f4() noexcept(true); |
| 70 |
__declspec(nothrow) void f5() noexcept(false); |
| 71 |
}; |
| 72 |
|
| 73 |
namespace PR42100 { |
| 74 |
class Base { |
| 75 |
public: |
| 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(); |
| 80 |
}; |
| 81 |
|
| 82 |
// expected-warning@+1{{'bar' is missing exception specification '__attribute__((nothrow))'}} |
| 83 |
void Base::bar() {} |
| 84 |
|
| 85 |
class Sub : public Base { |
| 86 |
public: |
| 87 |
// expected-warning@+1{{exception specification of overriding function is more lax than base version}} |
| 88 |
void foo() {} |
| 89 |
}; |
| 90 |
} |
| 91 |
|
| 92 |
namespace FuncPointerReferenceConverts { |
| 93 |
void FuncToBeRefed(); |
| 94 |
|
| 95 |
#ifndef CPP17 |
| 96 |
// expected-error@+6{{target exception specification is not superset of source}} |
| 97 |
// expected-error@+6{{target exception specification is not superset of source}} |
| 98 |
#else |
| 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}} |
| 101 |
#endif |
| 102 |
__declspec(nothrow) void (&FuncRef)() = FuncToBeRefed; |
| 103 |
__declspec(nothrow) void (*FuncPtr)() = FuncToBeRefed; |
| 104 |
} |