1cfbfdd9b55f7c85f83aad51060d3818c559d2ca6Nico Weber//===--------------------- catch_const_pointer_nullptr.cpp ----------------===//
2cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow//
3cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow//                     The LLVM Compiler Infrastructure
4cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow//
5cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow// This file is dual licensed under the MIT and the University of Illinois Open
6cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow// Source Licenses. See LICENSE.TXT for details.
7cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow//
8cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow//===----------------------------------------------------------------------===//
9cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
10cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow#include <cassert>
11cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
12cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow#if __has_feature(cxx_nullptr)
13cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
14cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowstruct A {};
15cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
16cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test1()
17cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
18cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    try
19cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
20cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        throw nullptr;
21cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
22cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
23cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A*)
24cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
25cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
26cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (const A*)
27cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
28cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
29cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
30cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
31cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
32cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
33cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test2()
34cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
35cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    try
36cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
37cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        throw nullptr;
38cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
39cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
40cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (const A*)
41cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
42cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
43cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A*)
44cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
45cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
46cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
47cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
48cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
49cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test3()
50cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
51cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    try
52cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
53cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        throw nullptr;
54cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
55cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
56c22004f1433b5cdd93403e1a048de21566604cd6Marshall Clow    catch (const A* const)
57cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
58cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
59cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A*)
60cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
61cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
62cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
63cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
64cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
65cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test4()
66cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
67cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    try
68cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
69cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        throw nullptr;
70cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
71cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
72cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A*)
73cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
74cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
75c22004f1433b5cdd93403e1a048de21566604cd6Marshall Clow    catch (const A* const)
76cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
77cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
78cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
79cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
80cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
81cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test5()
82cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
83cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    try
84cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
85cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        throw nullptr;
86cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
87cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
88cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A const*)
89cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
90cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
91cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A*)
92cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
93cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
94cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
95cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
96cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
97cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test6()
98cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
99cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    try
100cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
101cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        throw nullptr;
102cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
103cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
104cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A*)
105cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
106cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
107cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    catch (A const*)
108cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    {
109cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow        assert(false);
110cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    }
111cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
112cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
113cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
114cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow#else
115cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
116cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test1() {}
117cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test2() {}
118cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test3() {}
119cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test4() {}
120cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test5() {}
121cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowvoid test6() {}
122cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
123cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow#endif
124cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow
125cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clowint main()
126cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow{
127cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    test1();
128cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    test2();
129cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    test3();
130cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    test4();
131cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    test5();
132cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow    test6();
133cf95babcc4bf55cb4d31f993b156d422f4d71d43Marshall Clow}
134