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 14*f5ff11c4SEric Fiselier // Clang emits warnings about exceptions of type 'Child' being caught by 15*f5ff11c4SEric Fiselier // an earlier handler of type 'Base'. Congrats clang, you've just 16*f5ff11c4SEric Fiselier // diagnosed the behavior under test. 17*f5ff11c4SEric Fiselier #if defined(__clang__) 18*f5ff11c4SEric Fiselier #pragma clang diagnostic ignored "-Wexceptions" 19*f5ff11c4SEric Fiselier #endif 20*f5ff11c4SEric 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 } 32e434b34fSJonathan Roelofs catch (A*) 33e434b34fSJonathan Roelofs { 34e434b34fSJonathan Roelofs } 35e434b34fSJonathan Roelofs catch (const A*) 36e434b34fSJonathan Roelofs { 37e434b34fSJonathan Roelofs assert(false); 38e434b34fSJonathan Roelofs } 39e434b34fSJonathan Roelofs } 40e434b34fSJonathan Roelofs 41e434b34fSJonathan Roelofs 42e434b34fSJonathan Roelofs void test2() 43e434b34fSJonathan Roelofs { 44e434b34fSJonathan Roelofs try 45e434b34fSJonathan Roelofs { 46e434b34fSJonathan Roelofs throw nullptr; 47e434b34fSJonathan Roelofs assert(false); 48e434b34fSJonathan Roelofs } 49e434b34fSJonathan Roelofs catch (const A*) 50e434b34fSJonathan Roelofs { 51e434b34fSJonathan Roelofs } 52e434b34fSJonathan Roelofs catch (A*) 53e434b34fSJonathan Roelofs { 54e434b34fSJonathan Roelofs assert(false); 55e434b34fSJonathan Roelofs } 56e434b34fSJonathan Roelofs } 57e434b34fSJonathan Roelofs 58e434b34fSJonathan Roelofs void test3() 59e434b34fSJonathan Roelofs { 60e434b34fSJonathan Roelofs try 61e434b34fSJonathan Roelofs { 62e434b34fSJonathan Roelofs throw nullptr; 63e434b34fSJonathan Roelofs assert(false); 64e434b34fSJonathan Roelofs } 65e434b34fSJonathan Roelofs catch (const A* const) 66e434b34fSJonathan Roelofs { 67e434b34fSJonathan Roelofs } 68e434b34fSJonathan Roelofs catch (A*) 69e434b34fSJonathan Roelofs { 70e434b34fSJonathan Roelofs assert(false); 71e434b34fSJonathan Roelofs } 72e434b34fSJonathan Roelofs } 73e434b34fSJonathan Roelofs 74e434b34fSJonathan Roelofs void test4() 75e434b34fSJonathan Roelofs { 76e434b34fSJonathan Roelofs try 77e434b34fSJonathan Roelofs { 78e434b34fSJonathan Roelofs throw nullptr; 79e434b34fSJonathan Roelofs assert(false); 80e434b34fSJonathan Roelofs } 81e434b34fSJonathan Roelofs catch (A*) 82e434b34fSJonathan Roelofs { 83e434b34fSJonathan Roelofs } 84e434b34fSJonathan Roelofs catch (const A* const) 85e434b34fSJonathan Roelofs { 86e434b34fSJonathan Roelofs assert(false); 87e434b34fSJonathan Roelofs } 88e434b34fSJonathan Roelofs } 89e434b34fSJonathan Roelofs 90e434b34fSJonathan Roelofs void test5() 91e434b34fSJonathan Roelofs { 92e434b34fSJonathan Roelofs try 93e434b34fSJonathan Roelofs { 94e434b34fSJonathan Roelofs throw nullptr; 95e434b34fSJonathan Roelofs assert(false); 96e434b34fSJonathan Roelofs } 97e434b34fSJonathan Roelofs catch (A const*) 98e434b34fSJonathan Roelofs { 99e434b34fSJonathan Roelofs } 100e434b34fSJonathan Roelofs catch (A*) 101e434b34fSJonathan Roelofs { 102e434b34fSJonathan Roelofs assert(false); 103e434b34fSJonathan Roelofs } 104e434b34fSJonathan Roelofs } 105e434b34fSJonathan Roelofs 106e434b34fSJonathan Roelofs void test6() 107e434b34fSJonathan Roelofs { 108e434b34fSJonathan Roelofs try 109e434b34fSJonathan Roelofs { 110e434b34fSJonathan Roelofs throw nullptr; 111e434b34fSJonathan Roelofs assert(false); 112e434b34fSJonathan Roelofs } 113e434b34fSJonathan Roelofs catch (A*) 114e434b34fSJonathan Roelofs { 115e434b34fSJonathan Roelofs } 116e434b34fSJonathan Roelofs catch (A const*) 117e434b34fSJonathan Roelofs { 118e434b34fSJonathan Roelofs assert(false); 119e434b34fSJonathan Roelofs } 120e434b34fSJonathan Roelofs } 121e434b34fSJonathan Roelofs 122e434b34fSJonathan Roelofs 123e434b34fSJonathan Roelofs #else 124e434b34fSJonathan Roelofs 125e434b34fSJonathan Roelofs void test1() {} 126e434b34fSJonathan Roelofs void test2() {} 127e434b34fSJonathan Roelofs void test3() {} 128e434b34fSJonathan Roelofs void test4() {} 129e434b34fSJonathan Roelofs void test5() {} 130e434b34fSJonathan Roelofs void test6() {} 131e434b34fSJonathan Roelofs 132e434b34fSJonathan Roelofs #endif 133e434b34fSJonathan Roelofs 134e434b34fSJonathan Roelofs int main() 135e434b34fSJonathan Roelofs { 136e434b34fSJonathan Roelofs test1(); 137e434b34fSJonathan Roelofs test2(); 138e434b34fSJonathan Roelofs test3(); 139e434b34fSJonathan Roelofs test4(); 140e434b34fSJonathan Roelofs test5(); 141e434b34fSJonathan Roelofs test6(); 142e434b34fSJonathan Roelofs } 143