1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: no-exceptions
15 #include <type_traits>
19 template<typename T
, bool CanCatchNullptr
>
20 static void catch_nullptr_test() {
24 assert(CanCatchNullptr
&& !static_cast<bool>(p
));
26 assert(!CanCatchNullptr
);
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.
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>();