Skip to content

Commit 8643bdd

Browse files
committed
[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
1 parent e096a03 commit 8643bdd

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

libcxx/include/__functional/bind.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,28 @@ _LIBCPP_FUNC_VIS extern const __ph<7> _7;
6262
_LIBCPP_FUNC_VIS extern const __ph<8> _8;
6363
_LIBCPP_FUNC_VIS extern const __ph<9> _9;
6464
_LIBCPP_FUNC_VIS extern const __ph<10> _10;
65+
#elif _LIBCPP_STD_VER >= 17
66+
inline constexpr __ph<1> _1{};
67+
inline constexpr __ph<2> _2{};
68+
inline constexpr __ph<3> _3{};
69+
inline constexpr __ph<4> _4{};
70+
inline constexpr __ph<5> _5{};
71+
inline constexpr __ph<6> _6{};
72+
inline constexpr __ph<7> _7{};
73+
inline constexpr __ph<8> _8{};
74+
inline constexpr __ph<9> _9{};
75+
inline constexpr __ph<10> _10{};
6576
#else
66-
/* inline */ constexpr __ph<1> _1{};
67-
/* inline */ constexpr __ph<2> _2{};
68-
/* inline */ constexpr __ph<3> _3{};
69-
/* inline */ constexpr __ph<4> _4{};
70-
/* inline */ constexpr __ph<5> _5{};
71-
/* inline */ constexpr __ph<6> _6{};
72-
/* inline */ constexpr __ph<7> _7{};
73-
/* inline */ constexpr __ph<8> _8{};
74-
/* inline */ constexpr __ph<9> _9{};
75-
/* inline */ constexpr __ph<10> _10{};
77+
constexpr __ph<1> _1{};
78+
constexpr __ph<2> _2{};
79+
constexpr __ph<3> _3{};
80+
constexpr __ph<4> _4{};
81+
constexpr __ph<5> _5{};
82+
constexpr __ph<6> _6{};
83+
constexpr __ph<7> _7{};
84+
constexpr __ph<8> _8{};
85+
constexpr __ph<9> _9{};
86+
constexpr __ph<10> _10{};
7687
#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
7788

7889
} // namespace placeholders

libcxx/include/__memory/allocator_arg_t.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525

2626
struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; };
2727

28-
#ifndef _LIBCPP_CXX03_LANG
28+
#if _LIBCPP_STD_VER >= 17
29+
inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
30+
#elif !defined(_LIBCPP_CXX03_LANG)
31+
constexpr allocator_arg_t allocator_arg = allocator_arg_t();
32+
#endif
2933

30-
/* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
34+
#ifndef _LIBCPP_CXX03_LANG
3135

3236
// allocator construction
3337

libcxx/include/__mutex/tag_types.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ struct _LIBCPP_TYPE_VIS adopt_lock_t {
3131
explicit adopt_lock_t() = default;
3232
};
3333

34-
# if !defined(_LIBCPP_CXX03_LANG)
35-
/* inline */ constexpr defer_lock_t defer_lock = defer_lock_t();
36-
/* inline */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
37-
/* inline */ constexpr adopt_lock_t adopt_lock = adopt_lock_t();
34+
# if _LIBCPP_STD_VER >= 17
35+
inline constexpr defer_lock_t defer_lock = defer_lock_t();
36+
inline constexpr try_to_lock_t try_to_lock = try_to_lock_t();
37+
inline constexpr adopt_lock_t adopt_lock = adopt_lock_t();
38+
# elif !defined(_LIBCPP_CXX03_LANG)
39+
constexpr defer_lock_t defer_lock = defer_lock_t();
40+
constexpr try_to_lock_t try_to_lock = try_to_lock_t();
41+
constexpr adopt_lock_t adopt_lock = adopt_lock_t();
3842
# endif
3943

4044
_LIBCPP_END_NAMESPACE_STD

libcxx/include/__utility/piecewise_construct.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919

2020
struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
2121

22-
#if !defined(_LIBCPP_CXX03_LANG)
23-
/* inline */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
22+
#if _LIBCPP_STD_VER >= 17
23+
inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
24+
#elif !defined(_LIBCPP_CXX03_LANG)
25+
constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
2426
#endif
2527

2628
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)