1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -verify -std=c++11 %s
2c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregorstruct A { };
3c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregorstruct B { };
4b87786f045d798b070980c108c922e1475d27b15Douglas Gregorstruct C { };
5c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregor
6b87786f045d798b070980c108c922e1475d27b15Douglas Gregor// Destructor
7c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregorstruct X0 {
8c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregor  virtual ~X0() throw(A); // expected-note{{overridden virtual function is here}}
9c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregor};
10c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregorstruct X1 {
11c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregor  virtual ~X1() throw(B); // expected-note{{overridden virtual function is here}}
12c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregor};
13c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregorstruct X2 : public X0, public X1 { }; // expected-error 2{{exception specification of overriding function is more lax than base version}}
14c05babe58ca0fe825a2c4d362f132f409217e39aDouglas Gregor
15b87786f045d798b070980c108c922e1475d27b15Douglas Gregor// Copy-assignment operator.
16b87786f045d798b070980c108c922e1475d27b15Douglas Gregorstruct CA0 {
17b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  CA0 &operator=(const CA0&) throw(A);
18b87786f045d798b070980c108c922e1475d27b15Douglas Gregor};
19b87786f045d798b070980c108c922e1475d27b15Douglas Gregorstruct CA1 {
20b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  CA1 &operator=(const CA1&) throw(B);
21b87786f045d798b070980c108c922e1475d27b15Douglas Gregor};
22b87786f045d798b070980c108c922e1475d27b15Douglas Gregorstruct CA2 : CA0, CA1 { };
23b87786f045d798b070980c108c922e1475d27b15Douglas Gregor
24b87786f045d798b070980c108c922e1475d27b15Douglas Gregorvoid test_CA() {
25b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  CA2 &(CA2::*captr1)(const CA2&) throw(A, B) = &CA2::operator=;
26b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  CA2 &(CA2::*captr2)(const CA2&) throw(A, B, C) = &CA2::operator=;
27b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  CA2 &(CA2::*captr3)(const CA2&) throw(A) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}}
28b87786f045d798b070980c108c922e1475d27b15Douglas Gregor  CA2 &(CA2::*captr4)(const CA2&) throw(B) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}}
29b87786f045d798b070980c108c922e1475d27b15Douglas Gregor}
307a614d8380297fcd2bc23986241905d97222948cRichard Smith
317a614d8380297fcd2bc23986241905d97222948cRichard Smith// In-class member initializers.
327a614d8380297fcd2bc23986241905d97222948cRichard Smithstruct IC0 {
337a614d8380297fcd2bc23986241905d97222948cRichard Smith  int inClassInit = 0;
347a614d8380297fcd2bc23986241905d97222948cRichard Smith};
357a614d8380297fcd2bc23986241905d97222948cRichard Smithstruct IC1 {
367a614d8380297fcd2bc23986241905d97222948cRichard Smith  int inClassInit = (throw B(), 0);
377a614d8380297fcd2bc23986241905d97222948cRichard Smith};
387a614d8380297fcd2bc23986241905d97222948cRichard Smith// FIXME: the exception specification on the default constructor is wrong:
397a614d8380297fcd2bc23986241905d97222948cRichard Smith// we cannot currently compute the set of thrown types.
407a614d8380297fcd2bc23986241905d97222948cRichard Smithstatic_assert(noexcept(IC0()), "IC0() does not throw");
417a614d8380297fcd2bc23986241905d97222948cRichard Smithstatic_assert(!noexcept(IC1()), "IC1() throws");
426a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith
436a06e5ff3b680dcf7234d200309fd2400c478095Richard Smithnamespace PR13381 {
446a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  struct NoThrowMove {
456a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMove(const NoThrowMove &);
466a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMove(NoThrowMove &&) noexcept;
476a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMove &operator=(const NoThrowMove &);
486a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMove &operator=(NoThrowMove &&) noexcept;
496a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  };
506a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  struct NoThrowMoveOnly {
516a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMoveOnly(NoThrowMoveOnly &&) noexcept;
526a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMoveOnly &operator=(NoThrowMoveOnly &&) noexcept;
536a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  };
546a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  struct X {
556a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    const NoThrowMove a;
566a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    NoThrowMoveOnly b;
576a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith
586a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    static X val();
596a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith    static X &ref();
606a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  };
616a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  // These both perform a move, but that copy might throw, because it calls
626a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  // NoThrowMove's copy constructor (because PR13381::a is const).
636a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  static_assert(!noexcept(X(X::val())), "");
646a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith  static_assert(!noexcept(X::ref() = X::val()), "");
656a06e5ff3b680dcf7234d200309fd2400c478095Richard Smith}
66