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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 19 07:15:34 PDT 2023


Author: Louis Dionne
Date: 2023-03-19T10:14:32-04:00
New Revision: c0cde79e9e3b3c5bb54c55b0eabe8142674028a4

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

LOG: [libc++] Remove C++03 extensions for std::allocator_arg & friends

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.

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

Added: 
    

Modified: 
    libcxx/docs/ReleaseNotes.rst
    libcxx/include/__memory/allocator_arg_t.h
    libcxx/include/__mutex_base
    libcxx/include/__utility/piecewise_construct.h
    libcxx/include/condition_variable
    libcxx/include/experimental/__memory
    libcxx/include/future
    libcxx/include/mutex
    libcxx/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
    libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp
    libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index 386ecc904a9b8..aa14e6bfcd97d 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -73,6 +73,15 @@ Deprecations and Removals
   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
 ----------------------------------
 

diff  --git a/libcxx/include/__memory/allocator_arg_t.h b/libcxx/include/__memory/allocator_arg_t.h
index 15f8c98c4c90c..9e2d8c6311b64 100644
--- a/libcxx/include/__memory/allocator_arg_t.h
+++ b/libcxx/include/__memory/allocator_arg_t.h
@@ -25,9 +25,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 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
 

diff  --git a/libcxx/include/__mutex_base b/libcxx/include/__mutex_base
index 80621c88370c9..191955363a2d3 100644
--- a/libcxx/include/__mutex_base
+++ b/libcxx/include/__mutex_base
@@ -66,19 +66,15 @@ struct _LIBCPP_TYPE_VIS defer_lock_t { explicit defer_lock_t() = default; };
 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)

diff  --git a/libcxx/include/__utility/piecewise_construct.h b/libcxx/include/__utility/piecewise_construct.h
index 3cc86fef2a0fb..071e207bd07ca 100644
--- a/libcxx/include/__utility/piecewise_construct.h
+++ b/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
 

diff  --git a/libcxx/include/condition_variable b/libcxx/include/condition_variable
index 85050dd064d4b..bb7b13c6fe3eb 100644
--- a/libcxx/include/condition_variable
+++ b/libcxx/include/condition_variable
@@ -202,7 +202,7 @@ condition_variable_any::wait(_Lock& __lock)
     unique_lock<mutex> __lk(*__mut);
     __lock.unlock();
     unique_ptr<_Lock, __lock_external> __lxx(&__lock);
-    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
+    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
     __cv_.wait(__lk);
 }  // __mut_.unlock(), __lock.lock()
 
@@ -224,7 +224,7 @@ condition_variable_any::wait_until(_Lock& __lock,
     unique_lock<mutex> __lk(*__mut);
     __lock.unlock();
     unique_ptr<_Lock, __lock_external> __lxx(&__lock);
-    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
+    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock_t());
     return __cv_.wait_until(__lk, __t);
 }  // __mut_.unlock(), __lock.lock()
 

diff  --git a/libcxx/include/experimental/__memory b/libcxx/include/experimental/__memory
index d7b031df502b9..b11369632ae15 100644
--- a/libcxx/include/experimental/__memory
+++ b/libcxx/include/experimental/__memory
@@ -93,7 +93,7 @@ template <class _Tp, class _Allocator, class... _Args>
 inline _LIBCPP_INLINE_VISIBILITY
 void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
 {
-    new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
+    new (__storage) _Tp (allocator_arg_t(), __a, _VSTD::forward<_Args>(__args)...);
 }
 
 // FIXME: This should have a version which takes a non-const alloc.

diff  --git a/libcxx/include/future b/libcxx/include/future
index cc7d1f93dd6f1..6f1eeff9cf1af 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -1906,8 +1906,8 @@ public:
               class = __enable_if_t<!is_same<__remove_cvref_t<_Fp>, packaged_task>::value> >
         _LIBCPP_INLINE_VISIBILITY
         packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
-             : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
-               __p_(allocator_arg, __a) {}
+             : __f_(allocator_arg_t(), __a, _VSTD::forward<_Fp>(__f)),
+               __p_(allocator_arg_t(), __a) {}
     // ~packaged_task() = default;
 
     // no copy
@@ -2021,8 +2021,8 @@ public:
               class = __enable_if_t<!is_same<__remove_cvref_t<_Fp>, packaged_task>::value> >
         _LIBCPP_INLINE_VISIBILITY
         packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
-             : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
-               __p_(allocator_arg, __a) {}
+             : __f_(allocator_arg_t(), __a, _VSTD::forward<_Fp>(__f)),
+               __p_(allocator_arg_t(), __a) {}
     // ~packaged_task() = default;
 
     // no copy

diff  --git a/libcxx/include/mutex b/libcxx/include/mutex
index 54104d5173d54..9d24768d6c0e2 100644
--- a/libcxx/include/mutex
+++ b/libcxx/include/mutex
@@ -328,7 +328,7 @@ template <class _L0, class _L1>
 _LIBCPP_HIDE_FROM_ABI int
 try_lock(_L0& __l0, _L1& __l1)
 {
-    unique_lock<_L0> __u0(__l0, try_to_lock);
+    unique_lock<_L0> __u0(__l0, try_to_lock_t());
     if (__u0.owns_lock())
     {
         if (__l1.try_lock())

diff  --git a/libcxx/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp b/libcxx/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp
index 02072f5e6f8a7..5d40fa71a4152 100644
--- a/libcxx/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp
+++ b/libcxx/test/libcxx/thread/thread.mutex/thread_safety_annotations_not_enabled.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
index cb105f20db597..4d11674f1e83c 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
index b2e80659abb35..4adbe26777d0b 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_adopt_lock.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
index fa00da655b0df..06ef2043edcef 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_defer_lock.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
index 39d3bde9c12a8..f4f344ef9b2c3 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.cons/mutex_try_to_lock.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 // ALLOW_RETRIES: 2
 
 // <mutex>

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
index b1b5af08d4df9..fa43f5dd874a5 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 // ALLOW_RETRIES: 2
 
 // <mutex>

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp
index 83e1d7eaa62fd..9249959ad005a 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
-//
+// UNSUPPORTED: c++03
 // ALLOW_RETRIES: 2
 
 // <mutex>

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp
index 1a0fba6146f5c..fe29d1625069e 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
index 3f6f2137fe24a..a1e8553b965fe 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp
index 2776e00aa31ad..bb4e9b4bf8af3 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/types.pass.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 //
 // UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03
 
 // <mutex>
 

diff  --git a/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp
index e22bec1e5144c..c1177445a3a6d 100644
--- a/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.tag/allocator_arg.pass.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: c++03
+
 // <memory>
 
 // struct allocator_arg_t { explicit allocator_arg_t() = default; };


        


More information about the libcxx-commits mailing list