// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall -Wno-unused-local-typedefs %s template struct ExceptionIf { static int f(); }; template<> struct ExceptionIf { typedef int f; }; // The exception specification of a defaulted default constructor depends on // the contents of in-class member initializers. However, the in-class member // initializers can depend on the exception specification of the constructor, // since the class is considered complete within them. We reject any such cases. namespace InClassInitializers { // Noexcept::Noexcept() is implicitly declared as noexcept(false), because it // directly invokes ThrowSomething(). However... // // If noexcept(Noexcept()) is false, then Noexcept() is a constant expression, // so noexcept(Noexcept()) is true. But if noexcept(Noexcept()) is true, then // Noexcept::Noexcept is not declared constexpr, therefore noexcept(Noexcept()) // is false. bool ThrowSomething() noexcept(false); struct ConstExpr { bool b = // expected-note {{declared here}} noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{default member initializer for 'b' needed}} }; // Much more obviously broken: we can't parse the initializer without already // knowing whether it produces a noexcept expression. struct TemplateArg { int n = // expected-note {{declared here}} ExceptionIf::f(); // expected-error {{default member initializer for 'n' needed}} }; // And within a nested class. struct Nested { struct Inner { int n = // expected-note {{declared here}} ExceptionIf::f(); } inner; // expected-error {{default member initializer for 'n' needed}} }; struct Nested2 { struct Inner; int n = Inner().n; // expected-error {{initializer for 'n' needed}} struct Inner { int n = ExceptionIf::f(); // expected-note {{declared here}} } inner; }; } namespace ExceptionSpecification { // FIXME: This diagnostic is quite useless; we should indicate whose // exception specification we were looking for and why. struct Nested { struct T { T() noexcept(!noexcept(Nested())); } t; // expected-error{{exception specification is not available until end of class definition}} }; } namespace DefaultArgument { struct Default { struct T { T(int = ExceptionIf struct A { A() noexcept(NE); A(const A&) noexcept(NE); A(A&&) noexcept(NE); A &operator=(const A&) noexcept(NE); A &operator=(A&&) noexcept(NE); ~A() noexcept(NE); }; template struct B : virtual A {}; template struct C : virtual A { virtual void f() = 0; // expected-note 2{{unimplemented}} }; template struct D final : C { void f(); }; template void check() { T *p = nullptr; T &a = *p; static_assert(noexcept(a = a) == D, ""); static_assert(noexcept(a = static_cast(a)) == E, ""); static_assert(noexcept(delete &a) == F, ""); // These are last because the first failure here causes instantiation to bail out. static_assert(noexcept(new (nothrow) T()) == A, ""); // expected-error 2{{abstract}} static_assert(noexcept(new (nothrow) T(a)) == B, ""); static_assert(noexcept(new (nothrow) T(static_cast(a))) == C, ""); } template void check, 0, 0, 0, 0, 0, 0>(); template void check, 1, 1, 1, 1, 1, 1>(); template void check, 0, 0, 0, 0, 0, 0>(); template void check, 1, 1, 1, 1, 1, 1>(); template void check, 1, 1, 1, 0, 0, 0>(); // expected-note {{instantiation}} template void check, 1, 1, 1, 1, 1, 1>(); // expected-note {{instantiation}} template void check, 0, 0, 0, 0, 0, 0>(); template void check, 1, 1, 1, 1, 1, 1>(); // ... the above trick doesn't work for this case... struct Cfalse : virtual A { virtual void f() = 0; Cfalse() noexcept; Cfalse(const Cfalse&) noexcept; Cfalse(Cfalse&&) noexcept; }; Cfalse::Cfalse() noexcept = default; Cfalse::Cfalse(const Cfalse&) noexcept = default; Cfalse::Cfalse(Cfalse&&) noexcept = default; }