1*eb8650a7SLouis Dionne //===----------------------------------------------------------------------===// 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 13f5ff11c4SEric Fiselier // Clang emits warnings about exceptions of type 'Child' being caught by 14f5ff11c4SEric Fiselier // an earlier handler of type 'Base'. Congrats clang, you've just 15f5ff11c4SEric Fiselier // diagnosed the behavior under test. 16f5ff11c4SEric Fiselier #if defined(__clang__) 17f5ff11c4SEric Fiselier #pragma clang diagnostic ignored "-Wexceptions" 18f5ff11c4SEric Fiselier #endif 19f5ff11c4SEric Fiselier 20e434b34fSJonathan Roelofs #if __has_feature(cxx_nullptr) 21e434b34fSJonathan Roelofs 22e434b34fSJonathan Roelofs struct A {}; 23e434b34fSJonathan Roelofs test1()24e434b34fSJonathan Roelofsvoid test1() 25e434b34fSJonathan Roelofs { 26e434b34fSJonathan Roelofs try 27e434b34fSJonathan Roelofs { 28e434b34fSJonathan Roelofs throw nullptr; 29e434b34fSJonathan Roelofs assert(false); 30e434b34fSJonathan Roelofs } 312f984cabSRichard Smith catch (A* p) 32e434b34fSJonathan Roelofs { 332f984cabSRichard Smith assert(!p); 34e434b34fSJonathan Roelofs } 35e434b34fSJonathan Roelofs catch (const A*) 36e434b34fSJonathan Roelofs { 37e434b34fSJonathan Roelofs assert(false); 38e434b34fSJonathan Roelofs } 39e434b34fSJonathan Roelofs } 40e434b34fSJonathan Roelofs 41e434b34fSJonathan Roelofs test2()42e434b34fSJonathan Roelofsvoid test2() 43e434b34fSJonathan Roelofs { 44e434b34fSJonathan Roelofs try 45e434b34fSJonathan Roelofs { 46e434b34fSJonathan Roelofs throw nullptr; 47e434b34fSJonathan Roelofs assert(false); 48e434b34fSJonathan Roelofs } 492f984cabSRichard Smith catch (const A* p) 50e434b34fSJonathan Roelofs { 512f984cabSRichard Smith assert(!p); 52e434b34fSJonathan Roelofs } 53e434b34fSJonathan Roelofs catch (A*) 54e434b34fSJonathan Roelofs { 55e434b34fSJonathan Roelofs assert(false); 56e434b34fSJonathan Roelofs } 57e434b34fSJonathan Roelofs } 58e434b34fSJonathan Roelofs test3()59e434b34fSJonathan Roelofsvoid test3() 60e434b34fSJonathan Roelofs { 61e434b34fSJonathan Roelofs try 62e434b34fSJonathan Roelofs { 63e434b34fSJonathan Roelofs throw nullptr; 64e434b34fSJonathan Roelofs assert(false); 65e434b34fSJonathan Roelofs } 662f984cabSRichard Smith catch (const A* const p) 67e434b34fSJonathan Roelofs { 682f984cabSRichard Smith assert(!p); 69e434b34fSJonathan Roelofs } 70e434b34fSJonathan Roelofs catch (A*) 71e434b34fSJonathan Roelofs { 72e434b34fSJonathan Roelofs assert(false); 73e434b34fSJonathan Roelofs } 74e434b34fSJonathan Roelofs } 75e434b34fSJonathan Roelofs test4()76e434b34fSJonathan Roelofsvoid test4() 77e434b34fSJonathan Roelofs { 78e434b34fSJonathan Roelofs try 79e434b34fSJonathan Roelofs { 80e434b34fSJonathan Roelofs throw nullptr; 81e434b34fSJonathan Roelofs assert(false); 82e434b34fSJonathan Roelofs } 832f984cabSRichard Smith catch (A* p) 84e434b34fSJonathan Roelofs { 852f984cabSRichard Smith assert(!p); 86e434b34fSJonathan Roelofs } 87e434b34fSJonathan Roelofs catch (const A* const) 88e434b34fSJonathan Roelofs { 89e434b34fSJonathan Roelofs assert(false); 90e434b34fSJonathan Roelofs } 91e434b34fSJonathan Roelofs } 92e434b34fSJonathan Roelofs test5()93e434b34fSJonathan Roelofsvoid test5() 94e434b34fSJonathan Roelofs { 95e434b34fSJonathan Roelofs try 96e434b34fSJonathan Roelofs { 97e434b34fSJonathan Roelofs throw nullptr; 98e434b34fSJonathan Roelofs assert(false); 99e434b34fSJonathan Roelofs } 1002f984cabSRichard Smith catch (A const* p) 101e434b34fSJonathan Roelofs { 1022f984cabSRichard Smith assert(!p); 103e434b34fSJonathan Roelofs } 104e434b34fSJonathan Roelofs catch (A*) 105e434b34fSJonathan Roelofs { 106e434b34fSJonathan Roelofs assert(false); 107e434b34fSJonathan Roelofs } 108e434b34fSJonathan Roelofs } 109e434b34fSJonathan Roelofs test6()110e434b34fSJonathan Roelofsvoid test6() 111e434b34fSJonathan Roelofs { 112e434b34fSJonathan Roelofs try 113e434b34fSJonathan Roelofs { 114e434b34fSJonathan Roelofs throw nullptr; 115e434b34fSJonathan Roelofs assert(false); 116e434b34fSJonathan Roelofs } 1172f984cabSRichard Smith catch (A* p) 118e434b34fSJonathan Roelofs { 1192f984cabSRichard Smith assert(!p); 120e434b34fSJonathan Roelofs } 121e434b34fSJonathan Roelofs catch (A const*) 122e434b34fSJonathan Roelofs { 123e434b34fSJonathan Roelofs assert(false); 124e434b34fSJonathan Roelofs } 125e434b34fSJonathan Roelofs } 126e434b34fSJonathan Roelofs 127e434b34fSJonathan Roelofs 128e434b34fSJonathan Roelofs #else 129e434b34fSJonathan Roelofs test1()130e434b34fSJonathan Roelofsvoid test1() {} test2()131e434b34fSJonathan Roelofsvoid test2() {} test3()132e434b34fSJonathan Roelofsvoid test3() {} test4()133e434b34fSJonathan Roelofsvoid test4() {} test5()134e434b34fSJonathan Roelofsvoid test5() {} test6()135e434b34fSJonathan Roelofsvoid test6() {} 136e434b34fSJonathan Roelofs 137e434b34fSJonathan Roelofs #endif 138e434b34fSJonathan Roelofs main(int,char **)139504bc07dSLouis Dionneint main(int, char**) { 140e434b34fSJonathan Roelofs test1(); 141e434b34fSJonathan Roelofs test2(); 142e434b34fSJonathan Roelofs test3(); 143e434b34fSJonathan Roelofs test4(); 144e434b34fSJonathan Roelofs test5(); 145e434b34fSJonathan Roelofs test6(); 146504bc07dSLouis Dionne 147504bc07dSLouis Dionne return 0; 148e434b34fSJonathan Roelofs } 149