1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++0x -Wall %s
3 template<bool b> struct ExceptionIf { static int f(); };
4 template<> struct ExceptionIf<false> { typedef int f; };
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...
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())
18 bool ThrowSomething() noexcept(false);
20 bool b = noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{exception specification is not available until end of class definition}}
23 bool w = noexcept(ConstExpr());
25 // Much more obviously broken: we can't parse the initializer without already
26 // knowing whether it produces a noexcept expression.
28 int n = ExceptionIf<noexcept(TemplateArg())>::f(); // expected-error {{exception specification is not available until end of class definition}}
30 bool x = noexcept(TemplateArg());
32 // And within a nested class.
35 int n = ExceptionIf<noexcept(Nested())>::f(); // expected-error {{exception specification is not available until end of class definition}}
38 bool y = noexcept(Nested());
39 bool z = noexcept(Nested::Inner());
43 // The same problem arises in delayed parsing of exception specifications,
44 // which clang does not yet support.
45 namespace ExceptionSpecification {
46 struct Nested { // expected-note {{not complete}}
48 T() noexcept(!noexcept(Nested())); // expected-error {{incomplete type}}
54 // The same problem arises in delayed parsing of default arguments,
55 // which clang does not yet support.
56 namespace DefaultArgument {
57 // FIXME: this diagnostic is completely wrong.
58 struct Default { // expected-note {{explicitly marked deleted here}}
60 T(int = ExceptionIf<noexcept(Default())::f()); // expected-error {{call to deleted constructor}}