Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxxabi / test / catch_reference_nullptr.pass.cpp
blobe9c3ba31b06b77278978920f2d0f04bbbac3df6c
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
10 // UNSUPPORTED: no-exceptions
12 #include <cassert>
13 #include <cstddef>
14 #include <cstdlib>
15 #include <type_traits>
17 struct A {};
19 template<typename T, bool CanCatchNullptr>
20 static void catch_nullptr_test() {
21 try {
22 throw nullptr;
23 } catch (T &p) {
24 assert(CanCatchNullptr && !static_cast<bool>(p));
25 } catch (...) {
26 assert(!CanCatchNullptr);
30 int main(int, char**)
32 static_assert(std::is_same<std::nullptr_t, decltype(nullptr)>::value, "");
34 // A reference to nullptr_t can catch nullptr.
35 catch_nullptr_test<std::nullptr_t, true>();
36 catch_nullptr_test<const std::nullptr_t, true>();
37 catch_nullptr_test<volatile std::nullptr_t, true>();
38 catch_nullptr_test<const volatile std::nullptr_t, true>();
40 // No other reference type can.
41 #if 0
42 // FIXME: These tests fail, because the ABI provides no way for us to
43 // distinguish this from catching by value.
44 catch_nullptr_test<void *, false>();
45 catch_nullptr_test<void * const, false>();
46 catch_nullptr_test<int *, false>();
47 catch_nullptr_test<A *, false>();
48 catch_nullptr_test<int A::*, false>();
49 catch_nullptr_test<int (A::*)(), false>();
50 #endif
52 return 0;