Skip to content

Commit effadd4

Browse files
authored
Merge pull request #242 from elbeno/workaround-clang-udl-bug
2 parents e5131a0 + 0735f7f commit effadd4

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

include/stdx/compiler.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
#endif
2323
#endif
2424

25+
#ifndef CONSTEVAL_UDL
26+
#if defined(__clang__)
27+
#define CONSTEVAL_UDL constexpr
28+
#else
29+
#define CONSTEVAL_UDL CONSTEVAL
30+
#endif
31+
#endif
32+
2533
#ifndef USING_ATTR_NS
2634
#if defined(__clang__)
2735
#define USING_ATTR_NS using clang:

include/stdx/ct_format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ template <typename Str> format_result(Str) -> format_result<Str, tuple<>>;
5555

5656
inline namespace literals {
5757
inline namespace ct_string_literals {
58-
template <ct_string S> CONSTEVAL auto operator""_fmt_res() {
58+
template <ct_string S> CONSTEVAL_UDL auto operator""_fmt_res() {
5959
return format_result{cts_t<S>{}};
6060
}
6161
} // namespace ct_string_literals

include/stdx/ct_string.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,11 @@ template <ct_string Value> CONSTEVAL auto ct() { return cts_t<Value>{}; }
162162

163163
inline namespace literals {
164164
inline namespace ct_string_literals {
165-
template <ct_string S> CONSTEVAL auto operator""_cts() { return S; }
165+
template <ct_string S> CONSTEVAL_UDL auto operator""_cts() { return S; }
166166

167-
template <ct_string S> CONSTEVAL auto operator""_ctst() { return cts_t<S>{}; }
167+
template <ct_string S> CONSTEVAL_UDL auto operator""_ctst() {
168+
return cts_t<S>{};
169+
}
168170
} // namespace ct_string_literals
169171
} // namespace literals
170172
} // namespace v1

include/stdx/tuple.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using index_constant = std::integral_constant<std::size_t, I>;
1818
template <std::size_t I> constexpr static index_constant<I> index{};
1919

2020
inline namespace literals {
21-
template <char... Chars> CONSTEVAL auto operator""_idx() {
21+
template <char... Chars> CONSTEVAL_UDL auto operator""_idx() {
2222
return index<parse_literal<std::size_t, Chars...>()>;
2323
}
2424
} // namespace literals

include/stdx/udls.hpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ template <auto I> using constant = std::integral_constant<decltype(I), I>;
7878
template <auto I> constexpr static constant<I> _c{};
7979

8080
inline namespace literals {
81-
template <char... Chars> CONSTEVAL auto operator""_c() {
81+
template <char... Chars> CONSTEVAL_UDL auto operator""_c() {
8282
return _c<parse_literal<std::uint32_t, Chars...>()>;
8383
}
8484
} // namespace literals
@@ -89,58 +89,60 @@ enum struct length_t : std::uint32_t {};
8989

9090
inline namespace literals {
9191
// NOLINTBEGIN(google-runtime-int)
92-
CONSTEVAL auto operator""_lsb(unsigned long long int n) -> lsb_t {
92+
CONSTEVAL_UDL auto operator""_lsb(unsigned long long int n) -> lsb_t {
9393
return static_cast<lsb_t>(n);
9494
}
95-
CONSTEVAL auto operator""_msb(unsigned long long int n) -> msb_t {
95+
CONSTEVAL_UDL auto operator""_msb(unsigned long long int n) -> msb_t {
9696
return static_cast<msb_t>(n);
9797
}
98-
CONSTEVAL auto operator""_len(unsigned long long int n) -> length_t {
98+
CONSTEVAL_UDL auto operator""_len(unsigned long long int n) -> length_t {
9999
return static_cast<length_t>(n);
100100
}
101101
// NOLINTEND(google-runtime-int)
102102
} // namespace literals
103103

104104
inline namespace literals {
105-
CONSTEVAL auto operator""_b(char const *, std::size_t) -> bool { return true; }
106-
CONSTEVAL auto operator""_true(char const *, std::size_t) -> bool {
105+
CONSTEVAL_UDL auto operator""_b(char const *, std::size_t) -> bool {
107106
return true;
108107
}
109-
CONSTEVAL auto operator""_false(char const *, std::size_t) -> bool {
108+
CONSTEVAL_UDL auto operator""_true(char const *, std::size_t) -> bool {
109+
return true;
110+
}
111+
CONSTEVAL_UDL auto operator""_false(char const *, std::size_t) -> bool {
110112
return false;
111113
}
112114

113115
// NOLINTBEGIN(google-runtime-int)
114-
CONSTEVAL auto operator""_k(unsigned long long int n)
116+
CONSTEVAL_UDL auto operator""_k(unsigned long long int n)
115117
-> unsigned long long int {
116118
return n * 1'000u;
117119
}
118-
CONSTEVAL auto operator""_M(unsigned long long int n)
120+
CONSTEVAL_UDL auto operator""_M(unsigned long long int n)
119121
-> unsigned long long int {
120122
return n * 1'000'000u;
121123
}
122-
CONSTEVAL auto operator""_G(unsigned long long int n)
124+
CONSTEVAL_UDL auto operator""_G(unsigned long long int n)
123125
-> unsigned long long int {
124126
return n * 1'000'000'000u;
125127
}
126128

127-
CONSTEVAL auto operator""_ki(unsigned long long int n)
129+
CONSTEVAL_UDL auto operator""_ki(unsigned long long int n)
128130
-> unsigned long long int {
129131
return n * 1'024u;
130132
}
131-
CONSTEVAL auto operator""_Mi(unsigned long long int n)
133+
CONSTEVAL_UDL auto operator""_Mi(unsigned long long int n)
132134
-> unsigned long long int {
133135
return n * 1'024ull * 1'024ull;
134136
}
135-
CONSTEVAL auto operator""_Gi(unsigned long long int n)
137+
CONSTEVAL_UDL auto operator""_Gi(unsigned long long int n)
136138
-> unsigned long long int {
137139
return n * 1'024ull * 1'024ull * 1'024ull;
138140
}
139141

140142
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
141143

142144
#define STDX_SMALL_INT_LITERAL_DEF(x) \
143-
CONSTEVAL auto operator""_##x(char const *, std::size_t) \
145+
CONSTEVAL_UDL auto operator""_##x(char const *, std::size_t) \
144146
->std::integral_constant<std::size_t, x##u> { \
145147
return {}; \
146148
}

0 commit comments

Comments
 (0)