1*eb8650a7SLouis Dionne //===----------------------------------------------------------------------===//
2e434b34fSJonathan Roelofs //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e434b34fSJonathan Roelofs //
7e434b34fSJonathan Roelofs //===----------------------------------------------------------------------===//
8e434b34fSJonathan Roelofs 
98c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
1057e446daSAsiri Rathnayake 
1160ba1fefSLouis Dionne // 1b00fc5d8133 made it in the dylib in macOS 10.11
12c360553cSLouis Dionne // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10}}
1360ba1fefSLouis Dionne 
14e434b34fSJonathan Roelofs #include <cassert>
15e434b34fSJonathan Roelofs 
16e434b34fSJonathan Roelofs struct A
17e434b34fSJonathan Roelofs {
AA18d1804db9SEric Fiselier     A() : i(0), j(0) {} // explicitly initialize 'i' to prevent warnings
19e434b34fSJonathan Roelofs     const int i;
20e434b34fSJonathan Roelofs     int j;
21e434b34fSJonathan Roelofs };
22e434b34fSJonathan Roelofs 
23e434b34fSJonathan Roelofs typedef const int A::*md1;
24e434b34fSJonathan Roelofs typedef       int A::*md2;
25e434b34fSJonathan Roelofs 
261b00fc5dSEric Fiselier struct B : public A
271b00fc5dSEric Fiselier {
BB28d1804db9SEric Fiselier     B() : k(0), l(0) {} // explicitly initialize 'k' to prevent warnings.
291b00fc5dSEric Fiselier     const int k;
301b00fc5dSEric Fiselier     int l;
311b00fc5dSEric Fiselier };
321b00fc5dSEric Fiselier 
331b00fc5dSEric Fiselier typedef const int B::*der1;
341b00fc5dSEric Fiselier typedef       int B::*der2;
351b00fc5dSEric Fiselier 
test1()36e434b34fSJonathan Roelofs void test1()
37e434b34fSJonathan Roelofs {
38e434b34fSJonathan Roelofs     try
39e434b34fSJonathan Roelofs     {
40e434b34fSJonathan Roelofs         throw &A::i;
41e434b34fSJonathan Roelofs         assert(false);
42e434b34fSJonathan Roelofs     }
43e434b34fSJonathan Roelofs     catch (md2)
44e434b34fSJonathan Roelofs     {
45e434b34fSJonathan Roelofs         assert(false);
46e434b34fSJonathan Roelofs     }
47e434b34fSJonathan Roelofs     catch (md1)
48e434b34fSJonathan Roelofs     {
49e434b34fSJonathan Roelofs     }
50e434b34fSJonathan Roelofs }
51e434b34fSJonathan Roelofs 
521b00fc5dSEric Fiselier // Check that cv qualified conversions are allowed.
test2()53e434b34fSJonathan Roelofs void test2()
54e434b34fSJonathan Roelofs {
55e434b34fSJonathan Roelofs     try
56e434b34fSJonathan Roelofs     {
57e434b34fSJonathan Roelofs         throw &A::j;
581b00fc5dSEric Fiselier     }
591b00fc5dSEric Fiselier     catch (md2)
601b00fc5dSEric Fiselier     {
611b00fc5dSEric Fiselier     }
621b00fc5dSEric Fiselier     catch (...)
631b00fc5dSEric Fiselier     {
641b00fc5dSEric Fiselier         assert(false);
651b00fc5dSEric Fiselier     }
661b00fc5dSEric Fiselier 
671b00fc5dSEric Fiselier     try
681b00fc5dSEric Fiselier     {
691b00fc5dSEric Fiselier         throw &A::j;
701b00fc5dSEric Fiselier         assert(false);
711b00fc5dSEric Fiselier     }
721b00fc5dSEric Fiselier     catch (md1)
731b00fc5dSEric Fiselier     {
741b00fc5dSEric Fiselier     }
751b00fc5dSEric Fiselier     catch (...)
761b00fc5dSEric Fiselier     {
771b00fc5dSEric Fiselier         assert(false);
781b00fc5dSEric Fiselier     }
791b00fc5dSEric Fiselier }
801b00fc5dSEric Fiselier 
81b6030b9dSEric Fiselier // Check that Base -> Derived conversions are NOT allowed.
test3()821b00fc5dSEric Fiselier void test3()
831b00fc5dSEric Fiselier {
841b00fc5dSEric Fiselier     try
851b00fc5dSEric Fiselier     {
861b00fc5dSEric Fiselier         throw &A::i;
871b00fc5dSEric Fiselier         assert(false);
881b00fc5dSEric Fiselier     }
891b00fc5dSEric Fiselier     catch (md2)
901b00fc5dSEric Fiselier     {
911b00fc5dSEric Fiselier         assert(false);
921b00fc5dSEric Fiselier     }
931b00fc5dSEric Fiselier     catch (der2)
941b00fc5dSEric Fiselier     {
951b00fc5dSEric Fiselier         assert(false);
961b00fc5dSEric Fiselier     }
971b00fc5dSEric Fiselier     catch (der1)
981b00fc5dSEric Fiselier     {
99b6030b9dSEric Fiselier         assert(false);
1001b00fc5dSEric Fiselier     }
1011b00fc5dSEric Fiselier     catch (md1)
1021b00fc5dSEric Fiselier     {
1031b00fc5dSEric Fiselier     }
1041b00fc5dSEric Fiselier }
1051b00fc5dSEric Fiselier 
106b6030b9dSEric Fiselier // Check that Base -> Derived conversions NOT are allowed with different cv
1071b00fc5dSEric Fiselier // qualifiers.
test4()1081b00fc5dSEric Fiselier void test4()
1091b00fc5dSEric Fiselier {
1101b00fc5dSEric Fiselier     try
1111b00fc5dSEric Fiselier     {
1121b00fc5dSEric Fiselier         throw &A::j;
1131b00fc5dSEric Fiselier         assert(false);
1141b00fc5dSEric Fiselier     }
1151b00fc5dSEric Fiselier     catch (der2)
1161b00fc5dSEric Fiselier     {
1171b00fc5dSEric Fiselier         assert(false);
1181b00fc5dSEric Fiselier     }
1191b00fc5dSEric Fiselier     catch (der1)
1201b00fc5dSEric Fiselier     {
121b6030b9dSEric Fiselier         assert(false);
122b6030b9dSEric Fiselier     }
123b6030b9dSEric Fiselier     catch (md2)
124b6030b9dSEric Fiselier     {
1251b00fc5dSEric Fiselier     }
1261b00fc5dSEric Fiselier     catch (...)
1271b00fc5dSEric Fiselier     {
1281b00fc5dSEric Fiselier         assert(false);
1291b00fc5dSEric Fiselier     }
1301b00fc5dSEric Fiselier }
1311b00fc5dSEric Fiselier 
1321b00fc5dSEric Fiselier // Check that no Derived -> Base conversions are allowed.
test5()1331b00fc5dSEric Fiselier void test5()
1341b00fc5dSEric Fiselier {
1351b00fc5dSEric Fiselier     try
1361b00fc5dSEric Fiselier     {
1371b00fc5dSEric Fiselier         throw &B::k;
138e434b34fSJonathan Roelofs         assert(false);
139e434b34fSJonathan Roelofs     }
140e434b34fSJonathan Roelofs     catch (md1)
141e434b34fSJonathan Roelofs     {
142e434b34fSJonathan Roelofs         assert(false);
143e434b34fSJonathan Roelofs     }
144e434b34fSJonathan Roelofs     catch (md2)
145e434b34fSJonathan Roelofs     {
1461b00fc5dSEric Fiselier         assert(false);
1471b00fc5dSEric Fiselier     }
1481b00fc5dSEric Fiselier     catch (der1)
1491b00fc5dSEric Fiselier     {
1501b00fc5dSEric Fiselier     }
1511b00fc5dSEric Fiselier 
1521b00fc5dSEric Fiselier     try
1531b00fc5dSEric Fiselier     {
1541b00fc5dSEric Fiselier         throw &B::l;
1551b00fc5dSEric Fiselier         assert(false);
1561b00fc5dSEric Fiselier     }
1571b00fc5dSEric Fiselier     catch (md1)
1581b00fc5dSEric Fiselier     {
1591b00fc5dSEric Fiselier         assert(false);
1601b00fc5dSEric Fiselier     }
1611b00fc5dSEric Fiselier     catch (md2)
1621b00fc5dSEric Fiselier     {
1631b00fc5dSEric Fiselier         assert(false);
1641b00fc5dSEric Fiselier     }
1651b00fc5dSEric Fiselier     catch (der2)
1661b00fc5dSEric Fiselier     {
167e434b34fSJonathan Roelofs     }
168e434b34fSJonathan Roelofs }
169e434b34fSJonathan Roelofs 
main(int,char **)170504bc07dSLouis Dionne int main(int, char**)
171e434b34fSJonathan Roelofs {
172e434b34fSJonathan Roelofs     test1();
173e434b34fSJonathan Roelofs     test2();
1741b00fc5dSEric Fiselier     test3();
1751b00fc5dSEric Fiselier     test4();
1761b00fc5dSEric Fiselier     test5();
177504bc07dSLouis Dionne 
178504bc07dSLouis Dionne     return 0;
179e434b34fSJonathan Roelofs }
180