1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -verify -std=c++11 %s
8 virtual ~X0() throw(A
); // expected-note{{overridden virtual function is here}}
11 virtual ~X1() throw(B
); // expected-note{{overridden virtual function is here}}
13 struct X2
: public X0
, public X1
{ }; // expected-error 2{{exception specification of overriding function is more lax than base version}}
15 // Copy-assignment operator.
17 CA0
&operator=(const CA0
&) throw(A
);
20 CA1
&operator=(const CA1
&) throw(B
);
22 struct CA2
: CA0
, CA1
{ };
25 CA2
&(CA2::*captr1
)(const CA2
&) throw(A
, B
) = &CA2::operator=;
26 CA2
&(CA2::*captr2
)(const CA2
&) throw(A
, B
, C
) = &CA2::operator=;
27 CA2
&(CA2::*captr3
)(const CA2
&) throw(A
) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}}
28 CA2
&(CA2::*captr4
)(const CA2
&) throw(B
) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}}
31 // In-class member initializers.
36 int inClassInit
= (throw B(), 0);
38 // FIXME: the exception specification on the default constructor is wrong:
39 // we cannot currently compute the set of thrown types.
40 static_assert(noexcept(IC0()), "IC0() does not throw");
41 static_assert(!noexcept(IC1()), "IC1() throws");
45 NoThrowMove(const NoThrowMove
&);
46 NoThrowMove(NoThrowMove
&&) noexcept
;
47 NoThrowMove
&operator=(const NoThrowMove
&) const;
48 NoThrowMove
&operator=(NoThrowMove
&&) const noexcept
;
50 struct NoThrowMoveOnly
{
51 NoThrowMoveOnly(NoThrowMoveOnly
&&) noexcept
;
52 NoThrowMoveOnly
&operator=(NoThrowMoveOnly
&&) noexcept
;
61 // These both perform a move, but that copy might throw, because it calls
62 // NoThrowMove's copy constructor (because PR13381::a is const).
63 static_assert(!noexcept(X(X::val())), "");
64 static_assert(!noexcept(X::ref() = X::val()), "");
68 // Part of DR1351: the implicit exception-specification is noexcept(false) if
69 // the set of potential exceptions of the special member function contains
70 // "any". Hence it is compatible with noexcept(false).
72 ThrowingBase() noexcept(false);
73 ThrowingBase(const ThrowingBase
&) noexcept(false);
74 ThrowingBase(ThrowingBase
&&) noexcept(false);
75 ThrowingBase
&operator=(const ThrowingBase
&) noexcept(false);
76 ThrowingBase
&operator=(ThrowingBase
&&) noexcept(false);
77 ~ThrowingBase() noexcept(false);
79 struct Derived
: ThrowingBase
{
80 Derived() noexcept(false) = default;
81 Derived(const Derived
&) noexcept(false) = default;
82 Derived(Derived
&&) noexcept(false) = default;
83 Derived
&operator=(const Derived
&) noexcept(false) = default;
84 Derived
&operator=(Derived
&&) noexcept(false) = default;
85 ~Derived() noexcept(false) = default;
87 static_assert(!noexcept(Derived()), "");
88 static_assert(!noexcept(Derived(static_cast<Derived
&&>(d1
))), "");
89 static_assert(!noexcept(Derived(d1
)), "");
90 static_assert(!noexcept(d1
= static_cast<Derived
&&>(d1
)), "");
91 static_assert(!noexcept(d1
= d1
), "");
92 struct Derived2
: ThrowingBase
{
94 Derived2(const Derived2
&) = default;
95 Derived2(Derived2
&&) = default;
96 Derived2
&operator=(const Derived2
&) = default;
97 Derived2
&operator=(Derived2
&&) = default;
98 ~Derived2() = default;
100 static_assert(!noexcept(Derived2()), "");
101 static_assert(!noexcept(Derived2(static_cast<Derived2
&&>(d2
))), "");
102 static_assert(!noexcept(Derived2(d2
)), "");
103 static_assert(!noexcept(d2
= static_cast<Derived2
&&>(d2
)), "");
104 static_assert(!noexcept(d2
= d2
), "");
105 struct Derived3
: ThrowingBase
{
106 Derived3() noexcept(true) = default;
107 Derived3(const Derived3
&) noexcept(true) = default;
108 Derived3(Derived3
&&) noexcept(true) = default;
109 Derived3
&operator=(const Derived3
&) noexcept(true) = default;
110 Derived3
&operator=(Derived3
&&) noexcept(true) = default;
111 ~Derived3() noexcept(true) = default;
113 static_assert(noexcept(Derived3(), Derived3(Derived3()), Derived3(d3
), d3
= Derived3(), d3
= d3
), "");
116 namespace rdar13017229
{
121 struct Derived
: Base
{
123 Typo
foo(); // expected-error{{unknown type name 'Typo'}}
128 template<int> struct X
{};
130 Base(X
<0>) noexcept(true);
131 Base(X
<1>) noexcept(false);
132 Base(X
<2>) throw(X
<2>);
133 template<typename T
> Base(T
) throw(T
);
135 template<typename T
> struct Throw
{
138 struct Derived1
: Base
, X
<5> {
142 struct Derived2
: Base
, Throw
<X
<3>> {
145 struct Derived3
: Base
{
149 static_assert(noexcept(Derived1(X
<0>())), "");
150 static_assert(!noexcept(Derived1(X
<1>())), "");
151 static_assert(!noexcept(Derived1(X
<2>())), "");
152 static_assert(!noexcept(Derived2(X
<0>())), "");
153 static_assert(!noexcept(Derived3(X
<0>())), "");