buildscripts icon indicating copy to clipboard operation
buildscripts copied to clipboard

vcpkg: Compilation error when using fmt::styled with fmt::print

Open ghost opened this issue 1 year ago • 3 comments

The following error message is displayed during compilation (output.cpp:104):

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\include\xutility(1190,54):
error C2794: 'reference': is not a member of any direct or indirect base class of 'std::iterator_traits<fmt::v11::appender>'
error C2938: 'std::_Iter_ref_t' : Failed to specialize alias template
error C2062: type 'unknown-type' unexpected
error C3376: 'std::_Iterator_is_volatile': only static data member templates are allowed
error C2976: 'std::_Iter_copy_cat': too few template arguments
error C2039: '_Bitcopy_assignable': is not a member of '`global namespace''

Here is the latest version of format.h in the fmtlib:

namespace std {
template <> struct iterator_traits<fmt::appender> {
  using iterator_category = output_iterator_tag;
  using value_type = char;
  using reference = char&;
  using difference_type = fmt::appender::difference_type;
};
}  // namespace std

The version of format.h in vcpkg-export-20240826-223407.zip is as follows:

namespace std {
template <> struct iterator_traits<fmt::appender> {
  using iterator_category = output_iterator_tag;
  using value_type = char;
  // Missing reference and difference_type
};
}  // namespace std

My guess about the cause of the above error is that the missing reference and difference_type may be contributing factors, but I don't know how to resolve this issue. Simply removing the use of fmt::styled allows the compilation to succeed.

ghost avatar Sep 22 '24 07:09 ghost

That's a bug in fmtlib https://github.com/fmtlib/fmt/issues/4091

There is no new release of fmtlib yet so you can keep your workaround until they release a new version.

Ghabry avatar Sep 22 '24 09:09 Ghabry

The issue can be temporarily resolved by adding the missing using reference = char&;.

ghost avatar Sep 22 '24 10:09 ghost

I think it would be good to keep this open until we have either the next version of fmt in vcpkg or we would need to pin the version there. (That is pinning vcpkg version, since package versions can only be specified with some JSON file which we do not use)

carstene1ns avatar Sep 22 '24 11:09 carstene1ns