Skip to content

Commit 72b0ac1

Browse files
committed
🐛 Fix CX_WRAP for empty types
Problem: - When `CX_WRAP` wraps empty types, it doesn't turn them into `type_identity<T>`. Solution: - Move the emptiness check after the type check.
1 parent b9ed877 commit 72b0ac1

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

include/stdx/utility.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ constexpr auto cx_detect1(auto) { return 0; }
297297
STDX_PRAGMA(diagnostic push) \
298298
STDX_PRAGMA(diagnostic ignored "-Wold-style-cast") \
299299
if constexpr (::stdx::is_cx_value_v< \
300-
std::invoke_result_t<decltype(f)>> or \
301-
std::is_empty_v<std::invoke_result_t<decltype(f)>>) { \
300+
std::invoke_result_t<decltype(f)>>) { \
302301
return f(); \
303302
} else if constexpr (CX_DETECT(X)) { \
304303
if constexpr (decltype(::stdx::cxv_detail::is_type< \
@@ -310,6 +309,9 @@ constexpr auto cx_detect1(auto) { return 0; }
310309
decltype(::stdx::cxv_detail::type_of< \
311310
::stdx::cxv_detail::from_any(X)>())>{}; \
312311
}}; \
312+
} else if constexpr (std::is_empty_v< \
313+
std::invoke_result_t<decltype(f)>>) { \
314+
return f(); \
313315
} else { \
314316
return ::stdx::overload{::stdx::cxv_detail::cx_base{}, f}; \
315317
} \

test/utility.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ TEST_CASE("CX_WRAP type argument", "[utility]") {
364364
std::is_same_v<decltype(CX_WRAP(int)()), stdx::type_identity<int>>);
365365
}
366366

367+
TEST_CASE("CX_WRAP empty type argument", "[utility]") {
368+
using X = std::integral_constant<int, 17>;
369+
STATIC_REQUIRE(stdx::is_cx_value_v<decltype(CX_WRAP(X))>);
370+
STATIC_REQUIRE(
371+
std::is_same_v<decltype(CX_WRAP(X)()), stdx::type_identity<X>>);
372+
}
373+
367374
TEST_CASE("CX_WRAP integral_constant arg", "[utility]") {
368375
auto x = std::integral_constant<int, 17>{};
369376
STATIC_REQUIRE(std::is_same_v<decltype(CX_WRAP(x)), decltype(x)>);

0 commit comments

Comments
 (0)