1e434b34fSJonathan Roelofs //===----------------- catch_member_pointer_nullptr.cpp -------------------===//
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 
11e434b34fSJonathan Roelofs #include <cassert>
12e434b34fSJonathan Roelofs 
13e434b34fSJonathan Roelofs #if __has_feature(cxx_nullptr)
14e434b34fSJonathan Roelofs 
15e434b34fSJonathan Roelofs struct A
16e434b34fSJonathan Roelofs {
17e434b34fSJonathan Roelofs     const int i;
18e434b34fSJonathan Roelofs     int j;
19e434b34fSJonathan Roelofs };
20e434b34fSJonathan Roelofs 
21e434b34fSJonathan Roelofs typedef const int A::*md1;
22e434b34fSJonathan Roelofs typedef       int A::*md2;
23e434b34fSJonathan Roelofs 
24e434b34fSJonathan Roelofs void test1()
25e434b34fSJonathan Roelofs {
26e434b34fSJonathan Roelofs     try
27e434b34fSJonathan Roelofs     {
28e434b34fSJonathan Roelofs         throw nullptr;
29e434b34fSJonathan Roelofs         assert(false);
30e434b34fSJonathan Roelofs     }
312f984cabSRichard Smith     catch (md2 p)
32e434b34fSJonathan Roelofs     {
332f984cabSRichard Smith         assert(!p);
34e434b34fSJonathan Roelofs     }
35e434b34fSJonathan Roelofs     catch (md1)
36e434b34fSJonathan Roelofs     {
37e434b34fSJonathan Roelofs         assert(false);
38e434b34fSJonathan Roelofs     }
39e434b34fSJonathan Roelofs }
40e434b34fSJonathan Roelofs 
41e434b34fSJonathan Roelofs void test2()
42e434b34fSJonathan Roelofs {
43e434b34fSJonathan Roelofs     try
44e434b34fSJonathan Roelofs     {
45e434b34fSJonathan Roelofs         throw nullptr;
46e434b34fSJonathan Roelofs         assert(false);
47e434b34fSJonathan Roelofs     }
482f984cabSRichard Smith     catch (md1 p)
49e434b34fSJonathan Roelofs     {
502f984cabSRichard Smith         assert(!p);
51e434b34fSJonathan Roelofs     }
52e434b34fSJonathan Roelofs     catch (md2)
53e434b34fSJonathan Roelofs     {
54e434b34fSJonathan Roelofs         assert(false);
55e434b34fSJonathan Roelofs     }
56e434b34fSJonathan Roelofs }
57e434b34fSJonathan Roelofs 
58e434b34fSJonathan Roelofs #else
59e434b34fSJonathan Roelofs 
60e434b34fSJonathan Roelofs void test1()
61e434b34fSJonathan Roelofs {
62e434b34fSJonathan Roelofs }
63e434b34fSJonathan Roelofs 
64e434b34fSJonathan Roelofs void test2()
65e434b34fSJonathan Roelofs {
66e434b34fSJonathan Roelofs }
67e434b34fSJonathan Roelofs 
68e434b34fSJonathan Roelofs #endif
69e434b34fSJonathan Roelofs 
70*504bc07dSLouis Dionne int main(int, char**)
71e434b34fSJonathan Roelofs {
72e434b34fSJonathan Roelofs     test1();
73e434b34fSJonathan Roelofs     test2();
74*504bc07dSLouis Dionne 
75*504bc07dSLouis Dionne     return 0;
76e434b34fSJonathan Roelofs }
77