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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 21 14:47:52 PDT 2023


Author: Louis Dionne
Date: 2023-04-21T17:47:17-04:00
New Revision: 8643bdd0165c494f86222fe892a7785ef95e1750

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

LOG: [libc++] Make std::allocator_arg and friends conforming in C++17

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.

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

Added: 
    

Modified: 
    libcxx/include/__functional/bind.h
    libcxx/include/__memory/allocator_arg_t.h
    libcxx/include/__mutex/tag_types.h
    libcxx/include/__utility/piecewise_construct.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h
index 71ca6bd6a8807..8e5d598ad257b 100644
--- a/libcxx/include/__functional/bind.h
+++ b/libcxx/include/__functional/bind.h
@@ -62,17 +62,28 @@ _LIBCPP_FUNC_VIS extern const __ph<7>   _7;
 _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

diff  --git a/libcxx/include/__memory/allocator_arg_t.h b/libcxx/include/__memory/allocator_arg_t.h
index 74e995c9f1a8a..4d9c115f7293f 100644
--- a/libcxx/include/__memory/allocator_arg_t.h
+++ b/libcxx/include/__memory/allocator_arg_t.h
@@ -25,9 +25,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 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();
+#ifndef _LIBCPP_CXX03_LANG
 
 // allocator construction
 

diff  --git a/libcxx/include/__mutex/tag_types.h b/libcxx/include/__mutex/tag_types.h
index f941d5e1d8723..5242fd6661569 100644
--- a/libcxx/include/__mutex/tag_types.h
+++ b/libcxx/include/__mutex/tag_types.h
@@ -31,10 +31,14 @@ 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
 
 _LIBCPP_END_NAMESPACE_STD

diff  --git a/libcxx/include/__utility/piecewise_construct.h b/libcxx/include/__utility/piecewise_construct.h
index daf2005559d52..ad86badb66c8d 100644
--- a/libcxx/include/__utility/piecewise_construct.h
+++ b/libcxx/include/__utility/piecewise_construct.h
@@ -19,8 +19,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 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


        


More information about the libcxx-commits mailing list