[libcxx-commits] [PATCH] D145422: [libc++] Remove C++03 extensions for std::allocator_arg & friends

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 6 13:46:33 PST 2023


ldionne created this revision.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

As explained in the release note, libc++ used to provide various
global variables as an extension in C++03 mode. Unfortunately, that
made our definition non-conforming in all standard modes. This was
never a big problem until recently, since we are trying to support
C++20 Modules in libc++, and that requires cleaning up the definition
of these variables.

This change is the first in a series of changes to achieve our end goal.
This patch removes the ability for users to rely on the (incorrect)
definition of those global variables inside the shared library. The
plan is to then remove those definitions from the shared library
(which is an ABI break but I don't think it will have impact), and
finally to make our definition of those variables conforming in all
standard modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145422

Files:
  libcxx/docs/ReleaseNotes.rst
  libcxx/include/__memory/allocator_arg_t.h
  libcxx/include/__mutex_base
  libcxx/include/__utility/piecewise_construct.h


Index: libcxx/include/__utility/piecewise_construct.h
===================================================================
--- libcxx/include/__utility/piecewise_construct.h
+++ libcxx/include/__utility/piecewise_construct.h
@@ -18,9 +18,10 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
-#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
-extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
-#else
+
+#if defined(_LIBCPP_BUILDING_LIBRARY)
+extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;
+#elif !defined(_LIBCPP_CXX03_LANG)
 /* inline */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
 #endif
 
Index: libcxx/include/__mutex_base
===================================================================
--- libcxx/include/__mutex_base
+++ libcxx/include/__mutex_base
@@ -64,19 +64,15 @@
 struct _LIBCPP_TYPE_VIS try_to_lock_t { explicit try_to_lock_t() = default; };
 struct _LIBCPP_TYPE_VIS adopt_lock_t { explicit adopt_lock_t() = default; };
 
-#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
-
-extern _LIBCPP_EXPORTED_FROM_ABI const defer_lock_t  defer_lock;
+#  if defined(_LIBCPP_BUILDING_LIBRARY)
+extern _LIBCPP_EXPORTED_FROM_ABI const defer_lock_t defer_lock;
 extern _LIBCPP_EXPORTED_FROM_ABI const try_to_lock_t try_to_lock;
-extern _LIBCPP_EXPORTED_FROM_ABI const adopt_lock_t  adopt_lock;
-
-#else
-
-/* inline */ constexpr defer_lock_t  defer_lock  = defer_lock_t();
+extern _LIBCPP_EXPORTED_FROM_ABI const adopt_lock_t adopt_lock;
+#  elif !defined(_LIBCPP_CXX03_LANG)
+/* inline */ constexpr defer_lock_t defer_lock = defer_lock_t();
 /* inline */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
-/* inline */ constexpr adopt_lock_t  adopt_lock  = adopt_lock_t();
-
-#endif
+/* inline */ constexpr adopt_lock_t adopt_lock = adopt_lock_t();
+#  endif
 
 template <class _Mutex>
 class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable)
Index: libcxx/include/__memory/allocator_arg_t.h
===================================================================
--- libcxx/include/__memory/allocator_arg_t.h
+++ libcxx/include/__memory/allocator_arg_t.h
@@ -25,9 +25,9 @@
 
 struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; };
 
-#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
+#if defined(_LIBCPP_BUILDING_LIBRARY)
 extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
-#else
+#elif !defined(_LIBCPP_CXX03_LANG)
 /* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
 #endif
 
Index: libcxx/docs/ReleaseNotes.rst
===================================================================
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -70,6 +70,15 @@
   from the Standard since it was never used, the proper specialization to use
   instead is ``template<size_t N> struct formatter<charT[N], charT>``.
 
+- Libc++ used to provide some C++11 tag type global variables in C++03 as an extension, which are removed in
+  this release. Those variables were ``std::allocator_arg``, ``std::defer_lock``, ``std::try_to_lock``,
+  ``std::adopt_lock``, and ``std::piecewise_construct``. Note that the types associated to those variables are
+  still provided in C++03 as an extension (e.g. ``std::piecewise_construct_t``). Providing those variables in
+  C++03 mode made it impossible to define them properly -- C++11 mandated that they be ``constexpr`` variables,
+  which is impossible in C++03 mode. Furthermore, C++17 mandated that they be ``inline constexpr`` variables,
+  which led to ODR violations when mixed with the C++03 definition. Cleaning this up is required for libc++ to
+  make progress on support for C++20 modules.
+
 Upcoming Deprecations and Removals
 ----------------------------------
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145422.502786.patch
Type: text/x-patch
Size: 3992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230306/f1de6d9d/attachment-0001.bin>


More information about the libcxx-commits mailing list