[libcxx-commits] [libcxx] 157bbe6 - [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 7 14:51:12 PST 2022


Author: Louis Dionne
Date: 2022-02-07T17:51:05-05:00
New Revision: 157bbe6aea22e87c822f6cda3cd404b8f657dce4

URL: https://github.com/llvm/llvm-project/commit/157bbe6aea22e87c822f6cda3cd404b8f657dce4
DIFF: https://github.com/llvm/llvm-project/commit/157bbe6aea22e87c822f6cda3cd404b8f657dce4.diff

LOG: [libc++] Remove the ability to use the std::nullptr_t emulation in C++03 mode

Back in https://reviews.llvm.org/D109459, we stopped using the C++03
emulation for std::nullptr_t by default, which was an ABI break. We
still left a knob for users to turn it back on if they were broken by
the change, with a note that we would remove that knob after one release.

The time has now come to remove the knob and clean up the std::nullptr_t
emulation.

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

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes.rst
    libcxx/include/CMakeLists.txt
    libcxx/include/__config
    libcxx/include/__debug
    libcxx/include/__format/formatter_pointer.h
    libcxx/include/__memory/auto_ptr.h
    libcxx/include/__support/win32/locale_win32.h
    libcxx/include/cstddef
    libcxx/include/module.modulemap
    libcxx/include/stddef.h
    libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
    libcxx/utils/generate_private_header_tests.py

Removed: 
    libcxx/include/__nullptr


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index 867cb0fe6d8e0..6ad7fe906d3fc 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -44,5 +44,10 @@ API Changes
 ABI Changes
 -----------
 
+- The ``_LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION`` macro controlling whether we use an
+  emulation for ``std::nullptr_t`` in C++03 mode has been removed. After this change,
+  ``_LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION`` will not be honoured anymore and there
+  will be no way to opt back into the C++03 emulation of ``std::nullptr_t``.
+
 Build System Changes
 --------------------

diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 38e81a41b7fc4..01b769d0ff6c5 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -276,7 +276,6 @@ set(files
   __memory/voidify.h
   __mutex_base
   __node_handle
-  __nullptr
   __numeric/accumulate.h
   __numeric/adjacent_
diff erence.h
   __numeric/exclusive_scan.h

diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 14e96c9fd40b8..55bb6d61487d3 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -138,23 +138,6 @@
 #  endif
 #endif
 
-// By default, don't use a nullptr_t emulation type in C++03.
-//
-// This is technically an ABI break from previous releases, however it is
-// very unlikely to impact anyone. If a user is impacted by this break,
-// they can return to using the C++03 nullptr emulation by defining
-// _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION.
-//
-// This switch will be removed entirely in favour of never providing a
-// C++03 emulation after one release.
-//
-// IMPORTANT: IF YOU ARE READING THIS AND YOU TURN THIS MACRO ON, PLEASE LEAVE
-//            A COMMENT ON https://reviews.llvm.org/D109459 OR YOU WILL BE BROKEN
-//            IN THE FUTURE WHEN WE REMOVE THE ABILITY TO USE THE C++03 EMULATION.
-#ifndef _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION
-# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
-#endif
-
 #if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
 // Enable additional explicit instantiations of iostreams components. This
 // reduces the number of weak definitions generated in programs that use
@@ -534,12 +517,8 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_NORETURN __attribute__ ((noreturn))
 #endif
 
-#if !(__has_feature(cxx_nullptr))
-#  if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
-#    define nullptr __nullptr
-#  else
-#    define _LIBCPP_HAS_NO_NULLPTR
-#  endif
+#ifdef _LIBCPP_CXX03_LANG
+# define nullptr __nullptr
 #endif
 
 // Objective-C++ features (opt-in)

diff  --git a/libcxx/include/__debug b/libcxx/include/__debug
index ce78cb281c1d9..43554dee5c9ed 100644
--- a/libcxx/include/__debug
+++ b/libcxx/include/__debug
@@ -18,10 +18,6 @@
 #  pragma GCC system_header
 #endif
 
-#if defined(_LIBCPP_HAS_NO_NULLPTR)
-# include <cstddef>
-#endif
-
 #if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
 #   include <cstddef>
 #   include <cstdio>

diff  --git a/libcxx/include/__format/formatter_pointer.h b/libcxx/include/__format/formatter_pointer.h
index aa2eb641c6c6d..15b6764000a0e 100644
--- a/libcxx/include/__format/formatter_pointer.h
+++ b/libcxx/include/__format/formatter_pointer.h
@@ -20,7 +20,6 @@
 #include <__format/formatter_integral.h>
 #include <__format/parser_std_format_spec.h>
 #include <__iterator/access.h>
-#include <__nullptr>
 #include <cstdint>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/__memory/auto_ptr.h b/libcxx/include/__memory/auto_ptr.h
index a244aaa047e1a..163a46b631f0c 100644
--- a/libcxx/include/__memory/auto_ptr.h
+++ b/libcxx/include/__memory/auto_ptr.h
@@ -11,7 +11,6 @@
 #define _LIBCPP___MEMORY_AUTO_PTR_H
 
 #include <__config>
-#include <__nullptr>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header

diff  --git a/libcxx/include/__nullptr b/libcxx/include/__nullptr
deleted file mode 100644
index 73f07220587e4..0000000000000
--- a/libcxx/include/__nullptr
+++ /dev/null
@@ -1,61 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_NULLPTR
-#define _LIBCPP_NULLPTR
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#  pragma GCC system_header
-#endif
-
-#ifdef _LIBCPP_HAS_NO_NULLPTR
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-struct _LIBCPP_TEMPLATE_VIS nullptr_t
-{
-    void* __lx;
-
-    struct __nat {int __for_bool_;};
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
-
-    template <class _Tp>
-        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
-        operator _Tp* () const {return 0;}
-
-    template <class _Tp, class _Up>
-        _LIBCPP_INLINE_VISIBILITY
-        operator _Tp _Up::* () const {return 0;}
-
-    friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
-    friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
-};
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
-
-#define nullptr _VSTD::__get_nullptr_t()
-
-_LIBCPP_END_NAMESPACE_STD
-
-#else  // _LIBCPP_HAS_NO_NULLPTR
-
-namespace std
-{
-    typedef decltype(nullptr) nullptr_t;
-} // namespace std
-
-#endif // _LIBCPP_HAS_NO_NULLPTR
-
-#endif // _LIBCPP_NULLPTR

diff  --git a/libcxx/include/__support/win32/locale_win32.h b/libcxx/include/__support/win32/locale_win32.h
index dd8a6001d6805..3824d66c84db2 100644
--- a/libcxx/include/__support/win32/locale_win32.h
+++ b/libcxx/include/__support/win32/locale_win32.h
@@ -11,7 +11,7 @@
 #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
 
 #include <__config>
-#include <__nullptr>
+#include <cstddef>
 #include <locale.h> // _locale_t
 #include <stdio.h>
 

diff  --git a/libcxx/include/cstddef b/libcxx/include/cstddef
index 0aefea92ed597..57cecc7bd772a 100644
--- a/libcxx/include/cstddef
+++ b/libcxx/include/cstddef
@@ -34,18 +34,16 @@ Types:
 */
 
 #include <__config>
+#include <stddef.h>
 #include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
 
-// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
-#include_next <stddef.h>
-#include <__nullptr>
-
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+using ::nullptr_t;
 using ::ptr
diff _t _LIBCPP_USING_IF_EXISTS;
 using ::size_t _LIBCPP_USING_IF_EXISTS;
 

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 35c4777f83554..a182ded3f5498 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -990,7 +990,6 @@ module std [system] {
   module __mbstate_t         { private header "__mbstate_t.h"       export * }
   module __mutex_base        { private header "__mutex_base"        export * }
   module __node_handle       { private header "__node_handle"       export * }
-  module __nullptr           {         header "__nullptr"           export * }
   module __split_buffer      { private header "__split_buffer"      export * }
   module __std_stream        { private header "__std_stream"        export * }
   module __string            { private header "__string"            export * }

diff  --git a/libcxx/include/stddef.h b/libcxx/include/stddef.h
index fab0de60feace..19e344f2a0007 100644
--- a/libcxx/include/stddef.h
+++ b/libcxx/include/stddef.h
@@ -45,12 +45,7 @@
 #include_next <stddef.h>
 
 #ifdef __cplusplus
-
-extern "C++" {
-#include <__nullptr>
-using std::nullptr_t;
-}
-
+    typedef decltype(nullptr) nullptr_t;
 #endif
 
 #endif // _LIBCPP_STDDEF_H

diff  --git a/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp b/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
index b12e5c00638bf..f59cf2d883c25 100644
--- a/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
+++ b/libcxx/test/std/language.support/support.types/nullptr_t.pass.cpp
@@ -80,14 +80,9 @@ int main(int, char**)
         test_conversions<int A::*>();
     }
     {
-#ifdef _LIBCPP_HAS_NO_NULLPTR
+        // TODO: Enable this assertion when GCC compilers implements http://wg21.link/CWG583.
+#if !defined(TEST_COMPILER_GCC)
         static_assert(!has_less<std::nullptr_t>::value, "");
-        // FIXME: our C++03 nullptr emulation still allows for comparisons
-        // with other pointer types by way of the conversion operator.
-        //static_assert(!has_less<void*>::value, "");
-#else
-        // TODO Enable this assertion when all compilers implement core DR 583.
-        // static_assert(!has_less<std::nullptr_t>::value, "");
 #endif
         test_comparisons<std::nullptr_t>();
         test_comparisons<void*>();

diff  --git a/libcxx/utils/generate_private_header_tests.py b/libcxx/utils/generate_private_header_tests.py
index 18e0aced485aa..81051a9f5ea78 100755
--- a/libcxx/utils/generate_private_header_tests.py
+++ b/libcxx/utils/generate_private_header_tests.py
@@ -54,8 +54,7 @@ def is_still_public(path):
     return not rp.startswith('__support') and rp not in [
         "__bsd_locale_defaults.h", "__bsd_locale_fallbacks.h", "__config",
         "__config_site.in", "__debug", "__hash_table", "__functional_base",
-        "__libcpp_version", "__nullptr", "__threading_support", "__tree",
-        "__undef_macros"
+        "__libcpp_version", "__threading_support", "__tree", "__undef_macros"
     ]
 
 


        


More information about the libcxx-commits mailing list