[libcxx-commits] [PATCH] D143797: [libc++] Mark some variables as inline, per the spec

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 13 06:09:27 PST 2023


ldionne updated this revision to Diff 496950.
ldionne marked an inline comment as done.
ldionne added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143797/new/

https://reviews.llvm.org/D143797

Files:
  libcxx/include/__config
  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
@@ -21,7 +21,7 @@
 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
 #else
-/* inline */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
+_LIBCPP_INLINE_CONSTEXPR_VAR 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
@@ -72,9 +72,9 @@
 
 #else
 
-/* 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();
+_LIBCPP_INLINE_CONSTEXPR_VAR defer_lock_t  defer_lock  = defer_lock_t();
+_LIBCPP_INLINE_CONSTEXPR_VAR try_to_lock_t try_to_lock = try_to_lock_t();
+_LIBCPP_INLINE_CONSTEXPR_VAR adopt_lock_t  adopt_lock  = adopt_lock_t();
 
 #endif
 
Index: libcxx/include/__memory/allocator_arg_t.h
===================================================================
--- libcxx/include/__memory/allocator_arg_t.h
+++ libcxx/include/__memory/allocator_arg_t.h
@@ -28,7 +28,7 @@
 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
 #else
-/* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
+_LIBCPP_INLINE_CONSTEXPR_VAR allocator_arg_t allocator_arg = allocator_arg_t();
 #endif
 
 #ifndef _LIBCPP_CXX03_LANG
Index: libcxx/include/__functional/bind.h
===================================================================
--- libcxx/include/__functional/bind.h
+++ libcxx/include/__functional/bind.h
@@ -64,16 +64,16 @@
 _LIBCPP_FUNC_VIS extern const __ph<9>   _9;
 _LIBCPP_FUNC_VIS extern const __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{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<1>   _1{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<2>   _2{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<3>   _3{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<4>   _4{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<5>   _5{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<6>   _6{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<7>   _7{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<8>   _8{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<9>   _9{};
+_LIBCPP_INLINE_CONSTEXPR_VAR __ph<10> _10{};
 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
 
 } // namespace placeholders
Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -885,6 +885,12 @@
 #    define _LIBCPP_NODISCARD_AFTER_CXX17
 #  endif
 
+#  if _LIBCPP_STD_VER >= 17
+#    define _LIBCPP_INLINE_CONSTEXPR_VAR inline constexpr
+#  else
+#    define _LIBCPP_INLINE_CONSTEXPR_VAR constexpr // This technically leads to ODR violations, but they are benign.
+#  endif
+
 #  if __has_attribute(__no_destroy__)
 #    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
 #  else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143797.496950.patch
Type: text/x-patch
Size: 3707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230213/b78b9ddc/attachment.bin>


More information about the libcxx-commits mailing list