Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 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 = noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{exception specification is not available until end of class definition}} |
| 21 | }; |
| 22 | // We can use it now. |
| 23 | bool w = noexcept(ConstExpr()); |
| 24 | |
| 25 | // Much more obviously broken: we can't parse the initializer without already |
| 26 | // knowing whether it produces a noexcept expression. |
| 27 | struct TemplateArg { |
| 28 | int n = ExceptionIf<noexcept(TemplateArg())>::f(); // expected-error {{exception specification is not available until end of class definition}} |
| 29 | }; |
| 30 | bool x = noexcept(TemplateArg()); |
| 31 | |
| 32 | // And within a nested class. |
| 33 | struct Nested { |
| 34 | struct Inner { |
| 35 | int n = ExceptionIf<noexcept(Nested())>::f(); // expected-error {{exception specification is not available until end of class definition}} |
| 36 | } inner; |
| 37 | }; |
| 38 | bool y = noexcept(Nested()); |
| 39 | bool z = noexcept(Nested::Inner()); |
| 40 | } |
| 41 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 42 | namespace ExceptionSpecification { |
Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 43 | struct Nested { |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 44 | struct T { |
Douglas Gregor | 74e2fc3 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 45 | T() noexcept(!noexcept(Nested())); // expected-error{{exception specification is not available until end of class definition}} |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 46 | } t; |
| 47 | }; |
| 48 | } |
| 49 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 50 | namespace DefaultArgument { |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 51 | struct Default { |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 52 | struct T { |
Douglas Gregor | e4e68d4 | 2012-02-15 19:33:52 +0000 | [diff] [blame] | 53 | T(int = ExceptionIf<noexcept(Default())::f()); // expected-error {{call to implicitly-deleted default constructor}} |
Richard Smith | 6c4c36c | 2012-03-30 20:53:28 +0000 | [diff] [blame] | 54 | } t; // expected-note {{has no default constructor}} |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 55 | }; |
| 56 | } |
Richard Smith | a4156b8 | 2012-04-21 18:42:51 +0000 | [diff] [blame^] | 57 | |
| 58 | namespace ImplicitDtorExceptionSpec { |
| 59 | struct A { |
| 60 | virtual ~A(); |
| 61 | |
| 62 | struct Inner { |
| 63 | ~Inner() throw(); |
| 64 | }; |
| 65 | Inner inner; |
| 66 | }; |
| 67 | |
| 68 | struct B { |
| 69 | virtual ~B() {} // expected-note {{here}} |
| 70 | }; |
| 71 | |
| 72 | struct C : B { |
| 73 | virtual ~C() {} |
| 74 | A a; |
| 75 | }; |
| 76 | |
| 77 | struct D : B { |
| 78 | ~D(); // expected-error {{more lax than base}} |
| 79 | struct E { |
| 80 | ~E(); |
| 81 | struct F { |
| 82 | ~F() throw(A); |
| 83 | } f; |
| 84 | } e; |
| 85 | }; |
| 86 | } |