blob: 0f22ce0b7cebce89208fc7c818d2c4d86a953b1d [file] [log] [blame]
Richard Smith82da19d2016-12-08 02:49:07 +00001// RUN: %clang_cc1 -std=c++1z -verify %s -fexceptions -fcxx-exceptions -Wno-dynamic-exception-spec
Richard Smitheb7ef2e2016-10-20 21:53:09 +00002
3struct X {};
4struct Y : X {};
5
6using A = void (*)() noexcept;
7using B = void (*)();
8using C = void (X::*)() noexcept;
9using D = void (X::*)();
10using E = void (Y::*)() noexcept;
11using F = void (Y::*)();
12
13void f(A a, B b, C c, D d, E e, F f, bool k) {
14 a = k ? a : b; // expected-error {{different exception specifications}}
15 b = k ? a : b;
16
17 c = k ? c : d; // expected-error {{different exception specifications}}
18 d = k ? c : d;
19
20 e = k ? c : f; // expected-error {{different exception specifications}}
21 e = k ? d : e; // expected-error {{different exception specifications}}
22 f = k ? c : f;
23 f = k ? d : e;
24
25 const A ak = a;
26 const B bk = b;
27 const A &ak2 = k ? ak : ak;
28 const A &ak3 = k ? ak : bk; // expected-error {{could not bind}}
29 const B &bk3 = k ? ak : bk;
30}
31
32namespace dynamic_exception_spec {
33 // Prior to P0012, we had:
34 // "[...] the target entity shall allow at least the exceptions allowed
35 // by the source value in the assignment or initialization"
36 //
37 // There's really only one way we can coherently apply this to conditional
38 // expressions: this must hold no matter which branch was taken.
39 using X = void (*)() throw(int);
40 using Y = void (*)() throw(float);
41 using Z = void (*)() throw(int, float);
42 void g(X x, Y y, Z z, bool k) {
Richard Smith1be59c52016-10-22 01:32:19 +000043 x = k ? X() : Y(); // expected-warning {{not superset}}
44 y = k ? X() : Y(); // expected-warning {{not superset}}
Richard Smitheb7ef2e2016-10-20 21:53:09 +000045 z = k ? X() : Y();
46
Richard Smith1be59c52016-10-22 01:32:19 +000047 x = k ? x : y; // expected-warning {{not superset}}
48 y = k ? x : y; // expected-warning {{not superset}}
Richard Smitheb7ef2e2016-10-20 21:53:09 +000049 z = k ? x : y;
50 }
51}