blob: b5f1587f9f2b51e168f0e5bd1160074c5e6954c0 [file] [log] [blame]
Richard Smitheb7ef2e2016-10-20 21:53:09 +00001// RUN: %clang_cc1 -std=c++1z -verify %s -fexceptions -fcxx-exceptions
2
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) {
43 x = k ? X() : Y(); // expected-error {{not superset}}
44 y = k ? X() : Y(); // expected-error {{not superset}}
45 z = k ? X() : Y();
46
47 x = k ? x : y; // expected-error {{not superset}}
48 y = k ? x : y; // expected-error {{not superset}}
49 z = k ? x : y;
50 }
51}