Skip to content

Commit b9ed877

Browse files
elbenomjcaisse-intel
authored andcommitted
🎨 CX_WRAP should leave empty types alone
Problem: - `CX_WRAP` sometimes (on GCC) wraps empty types. In fact empty types (like `std::integral_constant` specializations) can be used as `constexpr` values just fine even when the "value" is not marked `constexpr`. Solution: - Detect empty types in `CX_WRAP` and leave them alone.
1 parent 526e301 commit b9ed877

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

include/stdx/utility.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ 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)>>) { \
300+
std::invoke_result_t<decltype(f)>> or \
301+
std::is_empty_v<std::invoke_result_t<decltype(f)>>) { \
301302
return f(); \
302303
} else if constexpr (CX_DETECT(X)) { \
303304
if constexpr (decltype(::stdx::cxv_detail::is_type< \

test/ct_format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,6 @@ TEST_CASE("FORMAT a constexpr string_view argument", "[ct_format]") {
298298
}
299299

300300
TEST_CASE("FORMAT an integral_constant argument", "[ct_format]") {
301-
constexpr static auto I = std::integral_constant<int, 17>{};
301+
auto I = std::integral_constant<int, 17>{};
302302
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", I) == "Hello 17"_fmt_res);
303303
}

test/utility.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,9 @@ 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 integral_constant arg", "[utility]") {
368+
auto x = std::integral_constant<int, 17>{};
369+
STATIC_REQUIRE(std::is_same_v<decltype(CX_WRAP(x)), decltype(x)>);
370+
CHECK(CX_WRAP(x)() == 17);
371+
}
367372
#endif

0 commit comments

Comments
 (0)