182da19ddSRichard Smith // RUN: %clang_cc1 -std=c++1z -verify %s -fexceptions -fcxx-exceptions -Wno-dynamic-exception-spec
2eb7ef2e1SRichard Smith
3eb7ef2e1SRichard Smith struct X {};
4eb7ef2e1SRichard Smith struct Y : X {};
5eb7ef2e1SRichard Smith
6eb7ef2e1SRichard Smith using A = void (*)() noexcept;
7eb7ef2e1SRichard Smith using B = void (*)();
8eb7ef2e1SRichard Smith using C = void (X::*)() noexcept;
9eb7ef2e1SRichard Smith using D = void (X::*)();
10eb7ef2e1SRichard Smith using E = void (Y::*)() noexcept;
11eb7ef2e1SRichard Smith using F = void (Y::*)();
12eb7ef2e1SRichard Smith
f(A a,B b,C c,D d,E e,F f,bool k)13eb7ef2e1SRichard Smith void f(A a, B b, C c, D d, E e, F f, bool k) {
14*fa755d3eSAnastasia Stulova a = k ? a : b; // expected-error {{incompatible function pointer types assigning to 'A' (aka 'void (*)() noexcept') from 'void (*)()'}}
15eb7ef2e1SRichard Smith b = k ? a : b;
16eb7ef2e1SRichard Smith
17eb7ef2e1SRichard Smith c = k ? c : d; // expected-error {{different exception specifications}}
18eb7ef2e1SRichard Smith d = k ? c : d;
19eb7ef2e1SRichard Smith
20eb7ef2e1SRichard Smith e = k ? c : f; // expected-error {{different exception specifications}}
21eb7ef2e1SRichard Smith e = k ? d : e; // expected-error {{different exception specifications}}
22eb7ef2e1SRichard Smith f = k ? c : f;
23eb7ef2e1SRichard Smith f = k ? d : e;
24eb7ef2e1SRichard Smith
25eb7ef2e1SRichard Smith const A ak = a;
26eb7ef2e1SRichard Smith const B bk = b;
27eb7ef2e1SRichard Smith const A &ak2 = k ? ak : ak;
28eb7ef2e1SRichard Smith const A &ak3 = k ? ak : bk; // expected-error {{could not bind}}
29eb7ef2e1SRichard Smith const B &bk3 = k ? ak : bk;
30eb7ef2e1SRichard Smith }
31eb7ef2e1SRichard Smith
32eb7ef2e1SRichard Smith namespace dynamic_exception_spec {
33eb7ef2e1SRichard Smith // Prior to P0012, we had:
34eb7ef2e1SRichard Smith // "[...] the target entity shall allow at least the exceptions allowed
35eb7ef2e1SRichard Smith // by the source value in the assignment or initialization"
36eb7ef2e1SRichard Smith //
37eb7ef2e1SRichard Smith // There's really only one way we can coherently apply this to conditional
38eb7ef2e1SRichard Smith // expressions: this must hold no matter which branch was taken.
39eb7ef2e1SRichard Smith using X = void (*)() throw(int);
40eb7ef2e1SRichard Smith using Y = void (*)() throw(float);
41eb7ef2e1SRichard Smith using Z = void (*)() throw(int, float);
g(X x,Y y,Z z,bool k)42eb7ef2e1SRichard Smith void g(X x, Y y, Z z, bool k) {
431be59c51SRichard Smith x = k ? X() : Y(); // expected-warning {{not superset}}
441be59c51SRichard Smith y = k ? X() : Y(); // expected-warning {{not superset}}
45eb7ef2e1SRichard Smith z = k ? X() : Y();
46eb7ef2e1SRichard Smith
471be59c51SRichard Smith x = k ? x : y; // expected-warning {{not superset}}
481be59c51SRichard Smith y = k ? x : y; // expected-warning {{not superset}}
49eb7ef2e1SRichard Smith z = k ? x : y;
50eb7ef2e1SRichard Smith }
51eb7ef2e1SRichard Smith }
52