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 
9*60ba1fefSLouis Dionne // Catching an exception thrown as nullptr was not properly handled before
10*60ba1fefSLouis Dionne // 2f984cab4fa7, which landed in macOS 10.13
11*60ba1fefSLouis Dionne // XFAIL: with_system_cxx_lib=macosx10.12
12*60ba1fefSLouis Dionne // XFAIL: with_system_cxx_lib=macosx10.11
13*60ba1fefSLouis Dionne // XFAIL: with_system_cxx_lib=macosx10.10
14*60ba1fefSLouis Dionne // XFAIL: with_system_cxx_lib=macosx10.9
15*60ba1fefSLouis Dionne 
168c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
1757e446daSAsiri Rathnayake 
18e434b34fSJonathan Roelofs #include <cassert>
19e434b34fSJonathan Roelofs 
20e434b34fSJonathan Roelofs #if __has_feature(cxx_nullptr)
21e434b34fSJonathan Roelofs 
22e434b34fSJonathan Roelofs struct A
23e434b34fSJonathan Roelofs {
24e434b34fSJonathan Roelofs     const int i;
25e434b34fSJonathan Roelofs     int j;
26e434b34fSJonathan Roelofs };
27e434b34fSJonathan Roelofs 
28e434b34fSJonathan Roelofs typedef const int A::*md1;
29e434b34fSJonathan Roelofs typedef       int A::*md2;
30e434b34fSJonathan Roelofs 
31e434b34fSJonathan Roelofs void test1()
32e434b34fSJonathan Roelofs {
33e434b34fSJonathan Roelofs     try
34e434b34fSJonathan Roelofs     {
35e434b34fSJonathan Roelofs         throw nullptr;
36e434b34fSJonathan Roelofs         assert(false);
37e434b34fSJonathan Roelofs     }
382f984cabSRichard Smith     catch (md2 p)
39e434b34fSJonathan Roelofs     {
402f984cabSRichard Smith         assert(!p);
41e434b34fSJonathan Roelofs     }
42e434b34fSJonathan Roelofs     catch (md1)
43e434b34fSJonathan Roelofs     {
44e434b34fSJonathan Roelofs         assert(false);
45e434b34fSJonathan Roelofs     }
46e434b34fSJonathan Roelofs }
47e434b34fSJonathan Roelofs 
48e434b34fSJonathan Roelofs void test2()
49e434b34fSJonathan Roelofs {
50e434b34fSJonathan Roelofs     try
51e434b34fSJonathan Roelofs     {
52e434b34fSJonathan Roelofs         throw nullptr;
53e434b34fSJonathan Roelofs         assert(false);
54e434b34fSJonathan Roelofs     }
552f984cabSRichard Smith     catch (md1 p)
56e434b34fSJonathan Roelofs     {
572f984cabSRichard Smith         assert(!p);
58e434b34fSJonathan Roelofs     }
59e434b34fSJonathan Roelofs     catch (md2)
60e434b34fSJonathan Roelofs     {
61e434b34fSJonathan Roelofs         assert(false);
62e434b34fSJonathan Roelofs     }
63e434b34fSJonathan Roelofs }
64e434b34fSJonathan Roelofs 
65e434b34fSJonathan Roelofs #else
66e434b34fSJonathan Roelofs 
67e434b34fSJonathan Roelofs void test1()
68e434b34fSJonathan Roelofs {
69e434b34fSJonathan Roelofs }
70e434b34fSJonathan Roelofs 
71e434b34fSJonathan Roelofs void test2()
72e434b34fSJonathan Roelofs {
73e434b34fSJonathan Roelofs }
74e434b34fSJonathan Roelofs 
75e434b34fSJonathan Roelofs #endif
76e434b34fSJonathan Roelofs 
77504bc07dSLouis Dionne int main(int, char**)
78e434b34fSJonathan Roelofs {
79e434b34fSJonathan Roelofs     test1();
80e434b34fSJonathan Roelofs     test2();
81504bc07dSLouis Dionne 
82504bc07dSLouis Dionne     return 0;
83e434b34fSJonathan Roelofs }
84