Skip to content

Commit ff96a19

Browse files
authored
Merge pull request #261 from elbeno/fix-typeof-use
🐛 Fix ICE with use of `__typeof__`
2 parents b48bac5 + 6b7e6d3 commit ff96a19

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

include/stdx/utility.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,23 @@ struct from_any {
145145
constexpr operator int() const { return 0; }
146146
};
147147

148+
struct value_marker {};
149+
148150
struct type_val {
149151
template <typename T, typename U,
150152
typename = std::enable_if_t<same_as_unqualified<type_val, U>>>
151153
friend constexpr auto operator+(T t, U const &) -> T {
152154
return t;
153155
}
154156
friend constexpr auto operator+(type_val const &f) -> type_val { return f; }
157+
158+
template <typename T, typename U,
159+
typename = std::enable_if_t<same_as_unqualified<type_val, U>>>
160+
friend constexpr auto operator*(T, U const &) -> value_marker {
161+
return {};
162+
}
163+
friend constexpr auto operator*(type_val const &f) -> type_val { return f; }
164+
155165
// NOLINTNEXTLINE(google-explicit-constructor)
156166
template <typename T> constexpr operator T() const {
157167
if constexpr (std::is_default_constructible_v<T>) {
@@ -164,7 +174,7 @@ struct type_val {
164174
};
165175

166176
template <typename> constexpr inline auto is_type = true;
167-
template <> constexpr inline auto is_type<from_any> = false;
177+
template <> constexpr inline auto is_type<value_marker> = false;
168178

169179
class cx_base {
170180
struct unusable {};
@@ -226,8 +236,8 @@ template <typename T> constexpr auto is_ct_v<T const> = is_ct_v<T>;
226236

227237
#ifndef STDX_IS_TYPE
228238
#define STDX_IS_TYPE(...) \
229-
::stdx::cxv_detail::is_type<__typeof__(::stdx::cxv_detail::from_any( \
230-
__VA_ARGS__))>
239+
::stdx::cxv_detail::is_type<decltype((__VA_ARGS__) * \
240+
::stdx::cxv_detail::type_val{})>
231241
#endif
232242

233243
#ifndef CX_VALUE

0 commit comments

Comments
 (0)