[libcxx-commits] [PATCH] D145589: [libc++] Make std::allocator_arg and friends conforming in C++17

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 8 08:04:29 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++.

This patch makes global tag variables like std::allocator_arg
conform to C++17 by defining them as inline constexpr variables.
This is possible without creating an ODR violation now that we don't
define strong definitions of those variables in the shared library
anymore.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145589

Files:
  libcxx/include/__functional/bind.h
  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
@@ -19,8 +19,10 @@
 
 struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
 
-#if !defined(_LIBCPP_CXX03_LANG)
-/* inline */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
+#if _LIBCPP_STD_VER >= 17
+inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
+#elif !defined(_LIBCPP_CXX03_LANG)
+constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
 #endif
 
 _LIBCPP_END_NAMESPACE_STD
Index: libcxx/include/__mutex_base
===================================================================
--- libcxx/include/__mutex_base
+++ libcxx/include/__mutex_base
@@ -64,10 +64,14 @@
 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)
-/* 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();
+#  if _LIBCPP_STD_VER >= 17
+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();
+#  elif !defined(_LIBCPP_CXX03_LANG)
+constexpr defer_lock_t defer_lock = defer_lock_t();
+constexpr try_to_lock_t try_to_lock = try_to_lock_t();
+constexpr adopt_lock_t adopt_lock = adopt_lock_t();
 #  endif
 
 template <class _Mutex>
Index: libcxx/include/__memory/allocator_arg_t.h
===================================================================
--- libcxx/include/__memory/allocator_arg_t.h
+++ libcxx/include/__memory/allocator_arg_t.h
@@ -25,7 +25,11 @@
 
 struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; };
 
-#ifndef _LIBCPP_CXX03_LANG
+#if _LIBCPP_STD_VER >= 17
+inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+#elif !defined(_LIBCPP_CXX03_LANG)
+constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+#endif
 
 /* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
 
Index: libcxx/include/__functional/bind.h
===================================================================
--- libcxx/include/__functional/bind.h
+++ libcxx/include/__functional/bind.h
@@ -63,17 +63,28 @@
 _LIBCPP_FUNC_VIS extern const __ph<8>   _8;
 _LIBCPP_FUNC_VIS extern const __ph<9>   _9;
 _LIBCPP_FUNC_VIS extern const __ph<10> _10;
+#elif _LIBCPP_STD_VER >= 17
+inline constexpr __ph<1>   _1{};
+inline constexpr __ph<2>   _2{};
+inline constexpr __ph<3>   _3{};
+inline constexpr __ph<4>   _4{};
+inline constexpr __ph<5>   _5{};
+inline constexpr __ph<6>   _6{};
+inline constexpr __ph<7>   _7{};
+inline constexpr __ph<8>   _8{};
+inline constexpr __ph<9>   _9{};
+inline constexpr __ph<10> _10{};
 #else
-/* inline */ constexpr __ph<1>   _1{};
-/* inline */ constexpr __ph<2>   _2{};
-/* inline */ constexpr __ph<3>   _3{};
-/* inline */ constexpr __ph<4>   _4{};
-/* inline */ constexpr __ph<5>   _5{};
-/* inline */ constexpr __ph<6>   _6{};
-/* inline */ constexpr __ph<7>   _7{};
-/* inline */ constexpr __ph<8>   _8{};
-/* inline */ constexpr __ph<9>   _9{};
-/* inline */ constexpr __ph<10> _10{};
+constexpr __ph<1>   _1{};
+constexpr __ph<2>   _2{};
+constexpr __ph<3>   _3{};
+constexpr __ph<4>   _4{};
+constexpr __ph<5>   _5{};
+constexpr __ph<6>   _6{};
+constexpr __ph<7>   _7{};
+constexpr __ph<8>   _8{};
+constexpr __ph<9>   _9{};
+constexpr __ph<10> _10{};
 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 
 } // namespace placeholders


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145589.503381.patch
Type: text/x-patch
Size: 3907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230308/24fdabe8/attachment.bin>


More information about the libcxx-commits mailing list