p14.cpp revision 762bb9d0ad20320b9f97a841dce57ba5e8e48b07
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"); 42