brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 3afb88b Raw
78 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310// UNSUPPORTED: no-exceptions11 12#include <cassert>13#include <cstdlib>14 15struct A {};16 17void test1()18{19    try20    {21        throw nullptr;22        assert(false);23    }24    catch (int* p)25    {26        assert(!p);27    }28    catch (long*)29    {30        assert(false);31    }32}33 34void test2()35{36    try37    {38        throw nullptr;39        assert(false);40    }41    catch (A* p)42    {43        assert(!p);44    }45    catch (int*)46    {47        assert(false);48    }49}50 51template <class Catch>52void catch_nullptr_test() {53  try {54    throw nullptr;55    assert(false);56  } catch (Catch c) {57    assert(!c);58  } catch (...) {59    assert(false);60  }61}62 63 64int main(int, char**)65{66  // catch naked nullptrs67  test1();68  test2();69 70  catch_nullptr_test<int*>();71  catch_nullptr_test<int**>();72  catch_nullptr_test<int A::*>();73  catch_nullptr_test<const int A::*>();74  catch_nullptr_test<int A::**>();75 76  return 0;77}78