1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall -Wno-unused-local-typedefs %s 2 3 template<bool b> struct ExceptionIf { static int f(); }; 4 template<> struct ExceptionIf<false> { typedef int f; }; 5 6 // The exception specification of a defaulted default constructor depends on 7 // the contents of in-class member initializers. However, the in-class member 8 // initializers can depend on the exception specification of the constructor, 9 // since the class is considered complete within them. We reject any such cases. 10 namespace InClassInitializers { 11 // Noexcept::Noexcept() is implicitly declared as noexcept(false), because it 12 // directly invokes ThrowSomething(). However... 13 // 14 // If noexcept(Noexcept()) is false, then Noexcept() is a constant expression, 15 // so noexcept(Noexcept()) is true. But if noexcept(Noexcept()) is true, then 16 // Noexcept::Noexcept is not declared constexpr, therefore noexcept(Noexcept()) 17 // is false. 18 bool ThrowSomething() noexcept(false); 19 struct ConstExpr { 20 bool b = // expected-note {{declared here}} 21 noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{default member initializer for 'b' needed}} 22 }; 23 24 // Much more obviously broken: we can't parse the initializer without already 25 // knowing whether it produces a noexcept expression. 26 struct TemplateArg { 27 int n = // expected-note {{declared here}} 28 ExceptionIf<noexcept(TemplateArg())>::f(); // expected-error {{default member initializer for 'n' needed}} 29 }; 30 31 // And within a nested class. 32 struct Nested { 33 struct Inner { 34 int n = // expected-note {{declared here}} 35 ExceptionIf<noexcept(Nested())>::f(); 36 } inner; // expected-error {{default member initializer for 'n' needed}} 37 }; 38 39 struct Nested2 { 40 struct Inner; 41 int n = Inner().n; // expected-error {{initializer for 'n' needed}} 42 struct Inner { 43 int n = ExceptionIf<noexcept(Nested2())>::f(); // expected-note {{declared here}} 44 } inner; 45 }; 46 } 47 48 namespace ExceptionSpecification { 49 // FIXME: This diagnostic is quite useless; we should indicate whose 50 // exception specification we were looking for and why. 51 struct Nested { 52 struct T { 53 T() noexcept(!noexcept(Nested())); 54 } t; // expected-error{{exception specification is not available until end of class definition}} 55 }; 56 } 57 58 namespace DefaultArgument { 59 struct Default { 60 struct T { 61 T(int = ExceptionIf<noexcept(Default())::f()); // expected-error {{call to implicitly-deleted default constructor}} 62 } t; // expected-note {{has no default constructor}} 63 }; 64 } 65 66 namespace ImplicitDtorExceptionSpec { 67 struct A { 68 virtual ~A(); 69 70 struct Inner { 71 ~Inner() throw(); 72 }; 73 Inner inner; 74 }; 75 76 struct B { 77 virtual ~B() {} // expected-note {{here}} 78 }; 79 80 struct C : B { 81 virtual ~C() {} 82 A a; 83 }; 84 85 struct D : B { 86 ~D(); // expected-error {{more lax than base}} 87 struct E { 88 ~E(); 89 struct F { 90 ~F() throw(A); 91 } f; 92 } e; 93 }; 94 } 95