1e434b34fSJonathan Roelofs //===--------------------- catch_const_pointer_nullptr.cpp ----------------===// 2e434b34fSJonathan Roelofs // 3e434b34fSJonathan Roelofs // The LLVM Compiler Infrastructure 4e434b34fSJonathan Roelofs // 5e434b34fSJonathan Roelofs // This file is dual licensed under the MIT and the University of Illinois Open 6e434b34fSJonathan Roelofs // Source Licenses. See LICENSE.TXT for details. 7e434b34fSJonathan Roelofs // 8e434b34fSJonathan Roelofs //===----------------------------------------------------------------------===// 9e434b34fSJonathan Roelofs 1057e446daSAsiri Rathnayake // UNSUPPORTED: libcxxabi-no-exceptions 1157e446daSAsiri Rathnayake 12e434b34fSJonathan Roelofs #include <cassert> 13e434b34fSJonathan Roelofs 14f5ff11c4SEric Fiselier // Clang emits warnings about exceptions of type 'Child' being caught by 15f5ff11c4SEric Fiselier // an earlier handler of type 'Base'. Congrats clang, you've just 16f5ff11c4SEric Fiselier // diagnosed the behavior under test. 17f5ff11c4SEric Fiselier #if defined(__clang__) 18f5ff11c4SEric Fiselier #pragma clang diagnostic ignored "-Wexceptions" 19f5ff11c4SEric Fiselier #endif 20f5ff11c4SEric Fiselier 21e434b34fSJonathan Roelofs #if __has_feature(cxx_nullptr) 22e434b34fSJonathan Roelofs 23e434b34fSJonathan Roelofs struct A {}; 24e434b34fSJonathan Roelofs 25e434b34fSJonathan Roelofs void test1() 26e434b34fSJonathan Roelofs { 27e434b34fSJonathan Roelofs try 28e434b34fSJonathan Roelofs { 29e434b34fSJonathan Roelofs throw nullptr; 30e434b34fSJonathan Roelofs assert(false); 31e434b34fSJonathan Roelofs } 32*2f984cabSRichard Smith catch (A* p) 33e434b34fSJonathan Roelofs { 34*2f984cabSRichard Smith assert(!p); 35e434b34fSJonathan Roelofs } 36e434b34fSJonathan Roelofs catch (const A*) 37e434b34fSJonathan Roelofs { 38e434b34fSJonathan Roelofs assert(false); 39e434b34fSJonathan Roelofs } 40e434b34fSJonathan Roelofs } 41e434b34fSJonathan Roelofs 42e434b34fSJonathan Roelofs 43e434b34fSJonathan Roelofs void test2() 44e434b34fSJonathan Roelofs { 45e434b34fSJonathan Roelofs try 46e434b34fSJonathan Roelofs { 47e434b34fSJonathan Roelofs throw nullptr; 48e434b34fSJonathan Roelofs assert(false); 49e434b34fSJonathan Roelofs } 50*2f984cabSRichard Smith catch (const A* p) 51e434b34fSJonathan Roelofs { 52*2f984cabSRichard Smith assert(!p); 53e434b34fSJonathan Roelofs } 54e434b34fSJonathan Roelofs catch (A*) 55e434b34fSJonathan Roelofs { 56e434b34fSJonathan Roelofs assert(false); 57e434b34fSJonathan Roelofs } 58e434b34fSJonathan Roelofs } 59e434b34fSJonathan Roelofs 60e434b34fSJonathan Roelofs void test3() 61e434b34fSJonathan Roelofs { 62e434b34fSJonathan Roelofs try 63e434b34fSJonathan Roelofs { 64e434b34fSJonathan Roelofs throw nullptr; 65e434b34fSJonathan Roelofs assert(false); 66e434b34fSJonathan Roelofs } 67*2f984cabSRichard Smith catch (const A* const p) 68e434b34fSJonathan Roelofs { 69*2f984cabSRichard Smith assert(!p); 70e434b34fSJonathan Roelofs } 71e434b34fSJonathan Roelofs catch (A*) 72e434b34fSJonathan Roelofs { 73e434b34fSJonathan Roelofs assert(false); 74e434b34fSJonathan Roelofs } 75e434b34fSJonathan Roelofs } 76e434b34fSJonathan Roelofs 77e434b34fSJonathan Roelofs void test4() 78e434b34fSJonathan Roelofs { 79e434b34fSJonathan Roelofs try 80e434b34fSJonathan Roelofs { 81e434b34fSJonathan Roelofs throw nullptr; 82e434b34fSJonathan Roelofs assert(false); 83e434b34fSJonathan Roelofs } 84*2f984cabSRichard Smith catch (A* p) 85e434b34fSJonathan Roelofs { 86*2f984cabSRichard Smith assert(!p); 87e434b34fSJonathan Roelofs } 88e434b34fSJonathan Roelofs catch (const A* const) 89e434b34fSJonathan Roelofs { 90e434b34fSJonathan Roelofs assert(false); 91e434b34fSJonathan Roelofs } 92e434b34fSJonathan Roelofs } 93e434b34fSJonathan Roelofs 94e434b34fSJonathan Roelofs void test5() 95e434b34fSJonathan Roelofs { 96e434b34fSJonathan Roelofs try 97e434b34fSJonathan Roelofs { 98e434b34fSJonathan Roelofs throw nullptr; 99e434b34fSJonathan Roelofs assert(false); 100e434b34fSJonathan Roelofs } 101*2f984cabSRichard Smith catch (A const* p) 102e434b34fSJonathan Roelofs { 103*2f984cabSRichard Smith assert(!p); 104e434b34fSJonathan Roelofs } 105e434b34fSJonathan Roelofs catch (A*) 106e434b34fSJonathan Roelofs { 107e434b34fSJonathan Roelofs assert(false); 108e434b34fSJonathan Roelofs } 109e434b34fSJonathan Roelofs } 110e434b34fSJonathan Roelofs 111e434b34fSJonathan Roelofs void test6() 112e434b34fSJonathan Roelofs { 113e434b34fSJonathan Roelofs try 114e434b34fSJonathan Roelofs { 115e434b34fSJonathan Roelofs throw nullptr; 116e434b34fSJonathan Roelofs assert(false); 117e434b34fSJonathan Roelofs } 118*2f984cabSRichard Smith catch (A* p) 119e434b34fSJonathan Roelofs { 120*2f984cabSRichard Smith assert(!p); 121e434b34fSJonathan Roelofs } 122e434b34fSJonathan Roelofs catch (A const*) 123e434b34fSJonathan Roelofs { 124e434b34fSJonathan Roelofs assert(false); 125e434b34fSJonathan Roelofs } 126e434b34fSJonathan Roelofs } 127e434b34fSJonathan Roelofs 128e434b34fSJonathan Roelofs 129e434b34fSJonathan Roelofs #else 130e434b34fSJonathan Roelofs 131e434b34fSJonathan Roelofs void test1() {} 132e434b34fSJonathan Roelofs void test2() {} 133e434b34fSJonathan Roelofs void test3() {} 134e434b34fSJonathan Roelofs void test4() {} 135e434b34fSJonathan Roelofs void test5() {} 136e434b34fSJonathan Roelofs void test6() {} 137e434b34fSJonathan Roelofs 138e434b34fSJonathan Roelofs #endif 139e434b34fSJonathan Roelofs 140e434b34fSJonathan Roelofs int main() 141e434b34fSJonathan Roelofs { 142e434b34fSJonathan Roelofs test1(); 143e434b34fSJonathan Roelofs test2(); 144e434b34fSJonathan Roelofs test3(); 145e434b34fSJonathan Roelofs test4(); 146e434b34fSJonathan Roelofs test5(); 147e434b34fSJonathan Roelofs test6(); 148e434b34fSJonathan Roelofs } 149