[PATCH] D41239: Turn a config macro (_LIBCPP_HAS_NO_INLINE_VARIABLES) into an attribute macro (_LIBCPP_INLINE_VAR)

Marshall Clow via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 14 07:33:12 PST 2017

mclow.lists created this revision.
mclow.lists added a reviewer: EricWF.

We're going to be defining a lot of inline variables going forward, and the current way of doing it is ... long-winded.
Add an attribute macro which we can put everywhere we need, and handles the conditional.

Instead of writing

  constexpr in_place_t in_place{};

we can now write:

  _LIBCPP_INLINE_VAR constexpr in_place_t in_place{};

(and it gets rid of a FIXME!)



Index: include/utility
--- include/utility
+++ include/utility
@@ -904,10 +904,7 @@
 struct _LIBCPP_TYPE_VIS in_place_t {
     explicit in_place_t() = default;
-constexpr in_place_t in_place{};
+_LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
@@ -914,10 +911,7 @@
     explicit in_place_type_t() = default;
 template <class _Tp>
-constexpr in_place_type_t<_Tp> in_place_type{};
+_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
 template <size_t _Idx>
 struct _LIBCPP_TYPE_VIS in_place_index_t {
@@ -924,10 +918,7 @@
     explicit in_place_index_t() = default;
 template <size_t _Idx>
-constexpr in_place_index_t<_Idx> in_place_index{};
+_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
 template <class _Tp> struct __is_inplace_type_imp : false_type {};
 template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
Index: include/__config
--- include/__config
+++ include/__config
@@ -978,9 +978,10 @@
-// FIXME: Remove all usages of this macro once compilers catch up.
-#if !defined(__cpp_inline_variables) || (__cpp_inline_variables < 201606L)
+#if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
+# define _LIBCPP_INLINE_VAR  inline
+# define _LIBCPP_INLINE_VAR  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41239.126956.patch
Type: text/x-patch
Size: 1829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171214/edbcb343/attachment.bin>

More information about the cfe-commits mailing list