[libcxx-commits] [libcxxabi] 2925333 - [libc++abi] Use std::nullptr_t instead of declaring it manually

Ryan Prichard via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 4 15:52:10 PDT 2022


Author: Ryan Prichard
Date: 2022-11-04T15:51:44-07:00
New Revision: 292533324cadf0164a7e1d532508cb59775e0a72

URL: https://github.com/llvm/llvm-project/commit/292533324cadf0164a7e1d532508cb59775e0a72
DIFF: https://github.com/llvm/llvm-project/commit/292533324cadf0164a7e1d532508cb59775e0a72.diff

LOG: [libc++abi] Use std::nullptr_t instead of declaring it manually

Sometimes libc++'s stddef.h wrapper gets included, which defines
::nullptr_t. This test is compiled with -Wshadow -Werror, so shadowing
::nullptr_t with a nullptr_t in main is an error. Include cstddef,
which is guaranteed to define std::nullptr_t in C++11 and forward.

Reviewed By: ldionne, #libc_abi

Differential Revision: https://reviews.llvm.org/D137127

Added: 
    

Modified: 
    libcxxabi/test/catch_reference_nullptr.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxxabi/test/catch_reference_nullptr.pass.cpp b/libcxxabi/test/catch_reference_nullptr.pass.cpp
index 708d5d798a1d1..e9c3ba31b06b7 100644
--- a/libcxxabi/test/catch_reference_nullptr.pass.cpp
+++ b/libcxxabi/test/catch_reference_nullptr.pass.cpp
@@ -6,11 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03,
+// UNSUPPORTED: c++03
 // UNSUPPORTED: no-exceptions
 
 #include <cassert>
+#include <cstddef>
 #include <cstdlib>
+#include <type_traits>
 
 struct A {};
 
@@ -27,13 +29,13 @@ static void catch_nullptr_test() {
 
 int main(int, char**)
 {
-  using nullptr_t = decltype(nullptr);
+  static_assert(std::is_same<std::nullptr_t, decltype(nullptr)>::value, "");
 
   // A reference to nullptr_t can catch nullptr.
-  catch_nullptr_test<nullptr_t, true>();
-  catch_nullptr_test<const nullptr_t, true>();
-  catch_nullptr_test<volatile nullptr_t, true>();
-  catch_nullptr_test<const volatile nullptr_t, true>();
+  catch_nullptr_test<std::nullptr_t, true>();
+  catch_nullptr_test<const std::nullptr_t, true>();
+  catch_nullptr_test<volatile std::nullptr_t, true>();
+  catch_nullptr_test<const volatile std::nullptr_t, true>();
 
   // No other reference type can.
 #if 0


        


More information about the libcxx-commits mailing list