Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::byte formatting with compile-time API is broken #2074

Closed
alexezeder opened this issue Dec 24, 2020 · 1 comment
Closed

std::byte formatting with compile-time API is broken #2074

alexezeder opened this issue Dec 24, 2020 · 1 comment

Comments

@alexezeder
Copy link
Contributor

alexezeder commented Dec 24, 2020

Right now formatting of std::byte using compile-time API like so:

fmt::format(FMT_COMPILE("{}"), std::byte{42})

ends up with compilation error, proof on Compiler Explorer. Because there are 2 write functions which satisfy for the passed type std::byte:

fmt/include/fmt/format.h

Lines 2114 to 2120 in 5a37e18

template <typename Char, typename OutputIt, typename T,
FMT_ENABLE_IF(std::is_enum<T>::value &&
!std::is_same<T, Char>::value)>
FMT_CONSTEXPR OutputIt write(OutputIt out, T value) {
return write<Char>(
out, static_cast<typename std::underlying_type<T>::type>(value));
}

fmt/include/fmt/format.h

Lines 2150 to 2162 in 5a37e18

template <typename Char, typename OutputIt, typename T>
auto write(OutputIt out, const T& value) -> typename std::enable_if<
mapped_type_constant<T, basic_format_context<OutputIt, Char>>::value ==
type::custom_type,
OutputIt>::type {
using context_type = basic_format_context<OutputIt, Char>;
using formatter_type =
conditional_t<has_formatter<T, context_type>::value,
typename context_type::template formatter_type<T>,
fallback_formatter<T, Char>>;
context_type ctx(out, {}, {});
return formatter_type().format(value, ctx);
}

I tried to fix that in the PR #2072 and with the SFINAE check for the enum-specific write function I ended up with a failed format-test because of a strange MSVC compiler error, which I cannot properly debug.

So feel free to create a new PR to fix that std::byte formatting bug with some MSVC workaround.

@alexezeder
Copy link
Contributor Author

It turned out that there are some workarounds for MSVC - https://godbolt.org/z/dvcTjj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants