105 lines · cpp
1// RUN: %clang_cc1 %s -fcxx-exceptions -fdeclspec -fsyntax-only -Wexceptions -verify -std=c++142// RUN: %clang_cc1 %s -fcxx-exceptions -fdeclspec -fsyntax-only -Wexceptions -verify -std=c++17 -DCPP173 4__attribute__((nothrow)) void f1();5static_assert(noexcept(f1()), "");6void f1() noexcept;7// expected-error@+2 {{exception specification in declaration does not match previous declaration}}8// expected-note@-2 {{previous declaration is here}}9void f1() noexcept(false);10 11__attribute__((nothrow)) void f2();12static_assert(noexcept(f2()), "");13// expected-error@+2 {{exception specification in declaration does not match previous declaration}}14// expected-note@-3 {{previous declaration is here}}15void f2() noexcept(false);16 17void f3() __attribute__((nothrow));18static_assert(noexcept(f3()), "");19void f3() noexcept;20// expected-error@+2 {{exception specification in declaration does not match previous declaration}}21// expected-note@-2 {{previous declaration is here}}22void f3() noexcept(false);23 24// Still noexcept due to throw()25__attribute__((nothrow)) void f4() throw();26static_assert(noexcept(f4()), "");27 28// Still noexcept due to noexcept29__attribute__((nothrow)) void f5() noexcept;30static_assert(noexcept(f5()), "");31 32// Still noexcept due to noexcept(true)33__attribute__((nothrow)) void f6() noexcept(true);34static_assert(noexcept(f6()), "");35 36#ifndef CPP1737// Doesn't override C++ implementation.38// expected-warning@+1{{'nothrow' attribute conflicts with exception specification; attribute ignored}}39__attribute__((nothrow)) void f7() throw(int);40static_assert(!noexcept(f7()), "");41#endif42 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);46static_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 57template<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 we61// evaluate the nothrow, these have yet to be parsed, so the data is not yet62// there.63struct S {64 __declspec(nothrow) void f1();65#ifndef CPP1766 __declspec(nothrow) void f2() throw();67 __declspec(nothrow) void f3() throw(int);68#endif69 __declspec(nothrow) void f4() noexcept(true);70 __declspec(nothrow) void f5() noexcept(false);71};72 73namespace PR42100 {74class Base {75public: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))'}}83void Base::bar() {}84 85class Sub : public Base {86public:87 // expected-warning@+1{{exception specification of overriding function is more lax than base version}}88 void foo() {}89};90}91 92namespace FuncPointerReferenceConverts {93void FuncToBeRefed();94 95#ifndef CPP1796// expected-error@+6{{target exception specification is not superset of source}}97// expected-error@+6{{target exception specification is not superset of source}}98#else99// 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#endif102__declspec(nothrow) void (&FuncRef)() = FuncToBeRefed;103__declspec(nothrow) void (*FuncPtr)() = FuncToBeRefed;104}105