[libc++][ABI BREAK] Do not use the C++03 emulation for std::nullptr_t by default

We only support Clangs that implement nullptr as an extension in C++03 mode,
and we don't support GCC in C++03 mode. Hence, this patch disables the
use of the std::nullptr_t emulation in C++03 mode by default. Doing that
is technically an ABI break since it changes the mangling for std::nullptr_t.
However:

(1) The only affected users are those compiling in C++03 mode that have
    std::nullptr_t as part of their ABI, which should be reasonably rare.

(2) Those users already have a lingering problem in that their code will
    be incompatible in C++03 and C++11 modes because of that very ABI break.
    Hence, the only users that could really be inconvenienced about this
    change is those that planned on compiling in C++03 mode forever - for
    other users, we're just breaking them now instead of letting them break
    themselves later on when they try to upgrade to C++11.

(3) The ABI break will cause a linker error since the mangling changed,
    and will not result in an obscure runtime error.

Furthermore, if anyone is broken by this, they can define the
_LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION macro to return to the
previous behavior. We will then remove that macro after shipping
this for one release if we haven't seen widespread issues.

Concretely, the motivation for making this change is to make our own ABI
consistent in C++03 and C++11 modes and to remove complexity around the
definition of nullptr.

Furthermore, we could investigate making nullptr a keyword in C++03 mode
as a Clang extension -- I don't think that would break anyone, since
libc++ already defines nullptr as a macro to something else. Only users
that do not use libc++ and compile in C++03 mode could potentially be
broken by that.

Differential Revision: https://reviews.llvm.org/D109459
This commit is contained in:
Louis Dionne 2021-11-29 16:20:48 -05:00
parent af059dfef5
commit a34f246899
2 changed files with 28 additions and 4 deletions

View File

@ -99,6 +99,17 @@ ABI Changes
- The C++17 variable templates ``is_error_code_enum_v`` and
``is_error_condition_enum_v`` are now of type ``bool`` instead of ``size_t``.
- The C++03 emulation type for ``std::nullptr_t`` has been removed in favor 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. However, previously, these users' ABI would be incompatible with any other
binary or static archive compiled with C++11 or later. If you start seeing linker
errors involving ``std::nullptr_t`` against previously compiled binaries, this may
be the cause. You can define the ``_LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION`` macro
to return to the previous behavior. That macro will be removed in LLVM 15. Please
comment `here <https://reviews.llvm.org/D109459>`_ if you are broken by this change
and need to define the macro.
Build System Changes
--------------------

View File

@ -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.
@ -127,6 +123,23 @@
# 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) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
// Enable additional explicit instantiations of iostreams components. This
// reduces the number of weak definitions generated in programs that use