diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -78,6 +78,11 @@ exceeds the maximum supported size, as required by the C++ standard. Previously the type ``std::length_error`` was used. +- The C++03 emulation type for ``std::nullptr_t`` has been removed in favour of + using ``decltype(nullptr)`` in all Standard modes. This is an ABI break for + anyone compiling in C++03 mode and who has ``std::nullptr_t`` as part of their + ABI. + Build System Changes -------------------- diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -230,7 +230,6 @@ __memory/uses_allocator.h __mutex_base __node_handle - __nullptr __random/uniform_int_distribution.h __ranges/access.h __ranges/all.h diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -74,10 +74,6 @@ # define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB # define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE -// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr -// provided under the alternate keyword __nullptr, which changes the mangling -// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode. -# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR // Define a key function for `bad_function_call` in the library, to centralize // its vtable and typeinfo to libc++ rather than having all other libraries // using that class define their own copies. @@ -459,12 +455,8 @@ # 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 --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -17,10 +17,6 @@ #pragma GCC system_header #endif -#if defined(_LIBCPP_HAS_NO_NULLPTR) -# include -#endif - #if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY) # include # include diff --git a/libcxx/include/__memory/auto_ptr.h b/libcxx/include/__memory/auto_ptr.h --- 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 --- a/libcxx/include/__nullptr +++ /dev/null @@ -1,61 +0,0 @@ -// -*- C++ -*- -//===--------------------------- __nullptr --------------------------------===// -// -// 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 - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - operator _Tp* () const {return 0;} - - template - _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; -} - -#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 --- 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 #include // _locale_t #include diff --git a/libcxx/include/cstddef b/libcxx/include/cstddef --- a/libcxx/include/cstddef +++ b/libcxx/include/cstddef @@ -34,18 +34,16 @@ */ #include <__config> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif -// Don't include our own ; we don't want to declare ::nullptr_t. -#include_next -#include <__nullptr> - _LIBCPP_BEGIN_NAMESPACE_STD +using ::nullptr_t; using ::ptrdiff_t _LIBCPP_USING_IF_EXISTS; using ::size_t _LIBCPP_USING_IF_EXISTS; diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -872,7 +872,6 @@ module __mbstate { 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 --- a/libcxx/include/stddef.h +++ b/libcxx/include/stddef.h @@ -45,12 +45,7 @@ #include_next #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 --- 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 @@ test_conversions(); } { -#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::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::value, ""); -#else - // TODO Enable this assertion when all compilers implement core DR 583. - // static_assert(!has_less::value, ""); #endif test_comparisons(); test_comparisons(); diff --git a/libcxx/utils/generate_private_header_tests.py b/libcxx/utils/generate_private_header_tests.py --- a/libcxx/utils/generate_private_header_tests.py +++ b/libcxx/utils/generate_private_header_tests.py @@ -54,8 +54,7 @@ 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" ]