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

new compilation error by upgrading from 11.0.1 to 11.1.2 with std::ostreambuf_iterator #4309

Closed
lano1106 opened this issue Jan 15, 2025 · 4 comments

Comments

@lano1106
Copy link

In file included from /usr/include/fmt/chrono.h:23,
                 from time_util.cpp:11:
/usr/include/fmt/format.h: In instantiation of ‘constexpr OutputIt fmt::v11::detail::write(OutputIt, T) [with Char = char; OutputIt = std::ostreambuf_iterator<char, std::char_traits<char> >; T = long int; typename std::enable_if<((is_integral<T>::value && (! std::is_same<T, bool>::value)) && (! std::is_same<T, Char>::value)), int>::type <anonymous> = 0]’:
/usr/include/fmt/compile.h:169:25:   required from ‘constexpr OutputIt fmt::v11::detail::field<Char, T, N>::format(OutputIt, const Args& ...) const [with OutputIt = std::ostreambuf_iterator<char, std::char_traits<char> >; Args = {long int, long int}; Char = char; T = long int; int N = 0]’
  169 |       return write<Char>(out, arg);
      |              ~~~~~~~~~~~^~~~~~~~~~
/usr/include/fmt/compile.h:234:21:   required from ‘constexpr OutputIt fmt::v11::detail::concat<L, R>::format(OutputIt, const Args& ...) const [with OutputIt = std::ostreambuf_iterator<char, std::char_traits<char> >; Args = {long int, long int}; L = fmt::v11::detail::field<char, long int, 0>; R = fmt::v11::detail::concat<fmt::v11::detail::code_unit<char>, fmt::v11::detail::spec_field<char, long int, 1> >]’
  234 |     out = lhs.format(out, args...);
      |           ~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/fmt/compile.h:460:19:   required from ‘constexpr OutputIt fmt::v11::format_to(OutputIt, const CompiledFormat&, const Args& ...) [with OutputIt = std::ostreambuf_iterator<char, std::char_traits<char> >; CompiledFormat = detail::concat<detail::field<char, long int, 0>, detail::concat<detail::code_unit<char>, detail::spec_field<char, long int, 1> > >; Args = {long int, long int}; typename std::enable_if<detail::is_compiled_format<CompiledFormat>::value, int>::type <anonymous> = 0]’
  460 |   return cf.format(out, args...);
      |          ~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/fmt/compile.h:500:26:   required from ‘constexpr OutputIt fmt::v11::format_to(OutputIt, const S&, Args&& ...) [with OutputIt = std::ostreambuf_iterator<char, std::char_traits<char> >; S = detail::udl_compiled_string<char, 10, detail::fixed_string<char, 10>{"{}.{:06d}"}>; Args = {const long int&, const long int&}; typename std::enable_if<detail::is_compiled_string<S>::value, int>::type <anonymous> = 0]’
  500 |     return fmt::format_to(out, compiled, std::forward<Args>(args)...);
      |            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
time_util.cpp:63:19:   required from here
   63 |     fmt::format_to(std::ostreambuf_iterator<char>{o}, "{}.{:06d}"_cf,
      |     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   64 |                ts.tv_sec, ts.tv_usec);
      |                ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/fmt/format.h:2168:30: error: no matching function for call to ‘format_decimal<char>(std::ostreambuf_iterator<char, std::char_traits<char> >&, long unsigned int&, int&)’
 2168 |   return format_decimal<Char>(out, abs_value, num_digits);
      |          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/fmt/format.h:1199:31: note: candidate: ‘template<class Char, class UInt> constexpr Char* fmt::v11::detail::format_decimal(Char*, UInt, int)’
 1199 | FMT_CONSTEXPR FMT_INLINE auto format_decimal(Char* out, UInt value,
      |                               ^~~~~~~~~~~~~~
/usr/include/fmt/format.h:1199:31: note:   template argument deduction/substitution failed:
/usr/include/fmt/format.h:2168:31: note:   cannot convert ‘out’ (type ‘std::ostreambuf_iterator<char, std::char_traits<char> >’) to type ‘char*’
 2168 |   return format_decimal<Char>(out, abs_value, num_digits);
      |                               ^~~
/usr/include/fmt/format.h:1207:20: note: candidate: ‘template<class Char, class UInt, class OutputIt, typename std::enable_if<fmt::v11::detail::is_back_insert_iterator<OutputIt>::value, int>::type <anonymous> > constexpr OutputIt fmt::v11::detail::format_decimal(OutputIt, UInt, int)’
 1207 | FMT_CONSTEXPR auto format_decimal(OutputIt out, UInt value, int num_digits)
      |                    ^~~~~~~~~~~~~~
/usr/include/fmt/format.h:1207:20: note:   template argument deduction/substitution failed:
In file included from /usr/include/fmt/format.h:41:
/usr/include/fmt/format.h:1206:11: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
 1206 |           FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
      |           ^~~~~~~~~~~~~
make: *** [Makefile:64: time_util.o] Error 1

I have locally fixed the problem by changing the fmt/formt.h template declaration from:

template <typename Char, typename UInt, typename OutputIt,
          FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
FMT_CONSTEXPR auto format_decimal(OutputIt out, UInt value, int num_digits)
    -> OutputIt {

to

template <typename Char, typename UInt, typename OutputIt>
FMT_CONSTEXPR auto format_decimal(OutputIt out, UInt value, int num_digits)
    -> OutputIt {
@vitaut
Copy link
Contributor

vitaut commented Jan 15, 2025

Please provide a godbolt repro.

@lano1106
Copy link
Author

lano1106 commented Jan 16, 2025

I am not sure why you need a godbolt repro... with my explanations, it is pretty obvious what is happening.
the format_decimal() template function is not enabled because std::ostreambuf_iterator is an output iterator and not a back_inserter_iterator.

format_decimal() does not need the iterator to be a back_inserter_iterator for the template function to work perfectly. I did not go as far as looking how it was done in 11.0.1 but I suspect that FMT_ENABLE_IF(is_back_insert_iterator::value) is an addition to 11.1

beside that, you made an excellent job in this new release by eliminating all those annoying linker warnings...

@phprus
Copy link
Contributor

phprus commented Jan 16, 2025

Maybe fixed by #4312

@lano1106
Copy link
Author

lano1106 commented Jan 16, 2025

by visual inspection, I would say that it does... I am just curious to know what the enable_if statement accomplish....

imho, it would be nice to document in a small comment...

I have solved my problem by totally removing it not knowing what was its purpose. It did not seem like the other format_decimal() overload presence could create any ambiguity for the compiler to choose which one to take...

@vitaut vitaut closed this as completed Jan 18, 2025
mtremer pushed a commit to ipfire/ipfire-2.x that referenced this issue Feb 22, 2025
- Update from version 11.0.2 to 11.1.3
- Update of rootfile
- Changelog
    11.1.3
	- Fixed compilation on GCC 9.4 (fmtlib/fmt#4313).
	- Worked around an internal compiler error when using C++20 modules with GCC
	  14.2 and earlier (fmtlib/fmt#4295).
	- Worked around a bug in GCC 6 (fmtlib/fmt#4318).
	- Fixed an issue caused by instantiating `formatter<const T>`
	  (fmtlib/fmt#4303,
	  fmtlib/fmt#4325). Thanks @timsong-cpp.
	- Fixed formatting into `std::ostreambuf_iterator` when using format string
	  compilation (fmtlib/fmt#4309,
	  fmtlib/fmt#4312). Thanks @phprus.
	- Restored a constraint on the map formatter so that it correctly reports as
	  unformattable when the element is (fmtlib/fmt#4326).
	  Thanks @timsong-cpp.
	- Reduced the size of format specs (fmtlib/fmt#4298).
	- Readded `args()` to `fmt::format_context`
	  (fmtlib/fmt#4307,
	  fmtlib/fmt#4310). Thanks @Erroneous1.
	- Fixed a bogus MSVC warning (fmtlib/fmt#4314,
	  fmtlib/fmt#4322). Thanks @ZehMatt.
	- Fixed a pedantic mode error in the CMake config
	  (fmtlib/fmt#4327). Thanks @rlalik.
    11.1.2
	- Fixed ABI compatibility with earlier 11.x versions
	  (fmtlib/fmt#4292).
	- Added `wchar_t` support to the `std::bitset` formatter
	  (fmtlib/fmt#4285,
	  fmtlib/fmt#4286,
	  fmtlib/fmt#4289,
	  fmtlib/fmt#4290). Thanks @phprus.
	- Prefixed CMake components with `fmt-` to simplify usage of {fmt} via
	  `add_subdirectory` (fmtlib/fmt#4283).
	- Updated docs for meson (fmtlib/fmt#4291).
	  Thanks @trim21.
	- Fixed a compilation error in chrono on nvcc
	  (fmtlib/fmt#4297,
	  fmtlib/fmt#4301). Thanks @breyerml.
	- Fixed various warnings
	  (fmtlib/fmt#4288,
	  fmtlib/fmt#4299). Thanks @GamesTrap and @edo9300.
    11.1.1
	- Fixed ABI compatibility with earlier 11.x versions
	  (fmtlib/fmt#4278).
	- Defined CMake components (`core` and `doc`) to allow docs to be installed
	  separately (fmtlib/fmt#4276).
	  Thanks @carlsmedstad.
    11.1.0
	- Improved C++20 module support
	  (fmtlib/fmt#4081,
	  fmtlib/fmt#4083,
	  fmtlib/fmt#4084,
	  fmtlib/fmt#4152,
	  fmtlib/fmt#4153,
	  fmtlib/fmt#4169,
	  fmtlib/fmt#4190,
	  fmtlib/fmt#4234,
	  fmtlib/fmt#4239).
	  Thanks @kamrann and @Arghnews.
	- Reduced debug (unoptimized) binary code size and the number of template
	  instantiations when passing formatting arguments. For example, unoptimized
	  binary code size for `fmt::print("{}", 42)` was reduced by ~40% on GCC and
	  ~60% on clang (x86-64).
	  GCC:
	  - Before: 161 instructions of which 105 are in reusable functions
	    ([godbolt](https://www.godbolt.org/z/s9bGoo4ze)).
	  - After: 116 instructions of which 60 are in reusable functions
	    ([godbolt](https://www.godbolt.org/z/r7GGGxMs6)).
	  Clang:
	  - Before: 310 instructions of which 251 are in reusable functions
	    ([godbolt](https://www.godbolt.org/z/Ts88b7M9o)).
	  - After: 194 instructions of which 135 are in reusable functions
	    ([godbolt](https://www.godbolt.org/z/vcrjP8ceW)).
	- Added an experimental `fmt::writer` API that can be used for writing to
	  different destinations such as files or strings
	  (fmtlib/fmt#2354).
	  For example ([godbolt](https://www.godbolt.org/z/rWoKfbP7e)):
		  ```c++
		  #include <fmt/os.h>
		  void write_text(fmt::writer w) {
		    w.print("The answer is {}.", 42);
		  }
		  int main() {
		    // Write to FILE.
		    write_text(stdout);
		    // Write to fmt::ostream.
		    auto f = fmt::output_file("myfile");
		    write_text(f);
		    // Write to std::string.
		    auto sb = fmt::string_buffer();
		    write_text(sb);
		    std::string s = sb.str();
		  }
		  ```
	- Added width and alignment support to the formatter of `std::error_code`.
	- Made `std::expected<void, E>` formattable
	  (fmtlib/fmt#4145,
	  fmtlib/fmt#4148).
	  For example ([godbolt](https://www.godbolt.org/z/hrj5c6G86)):
		  ```c++
		  fmt::print("{}", std::expected<void, int>());
		  ```
		  prints
		  ```
		  expected()
		  ```
	  Thanks @phprus.
	- Made `fmt::is_formattable<void>` SFINAE-friendly
	  (fmtlib/fmt#4147).
	- Added support for `_BitInt` formatting when using clang
	  (fmtlib/fmt#4007,
	  fmtlib/fmt#4072,
	  fmtlib/fmt#4140,
	  fmtlib/fmt#4173,
	  fmtlib/fmt#4176).
	  For example ([godbolt](https://www.godbolt.org/z/KWjbWec5z)):
		  ```c++
		  using int42 = _BitInt(42);
		  fmt::print("{}", int42(100));
		  ```
	  Thanks @Arghnews.
	- Added the `n` specifier for tuples and pairs
	  (fmtlib/fmt#4107). Thanks @someonewithpc.
	- Added support for tuple-like types to `fmt::join`
	  (fmtlib/fmt#4226,
	  fmtlib/fmt#4230). Thanks @phprus.
	- Made more types formattable at compile time
	  (fmtlib/fmt#4127). Thanks @AnthonyVH.
	- Implemented a more efficient compile-time `fmt::formatted_size`
	  (fmtlib/fmt#4102,
	  fmtlib/fmt#4103). Thanks @phprus.
	- Fixed compile-time formatting of some string types
	  (fmtlib/fmt#4065). Thanks @torshepherd.
	- Made compiled version of `fmt::format_to` work with
	  `std::back_insert_iterator<std::vector<char>>`
	  (fmtlib/fmt#4206,
	  fmtlib/fmt#4211). Thanks @phprus.
	- Added a formatter for `std::reference_wrapper`
	  (fmtlib/fmt#4163,
	  fmtlib/fmt#4164). Thanks @yfeldblum and @phprus.
	- Added experimental padding support (glibc `strftime` extension) to `%m`, `%j`
	  and `%Y` (fmtlib/fmt#4161). Thanks @KKhanhH.
	- Made microseconds formatted as `us` instead of `µs` if the Unicode support is
	  disabled (fmtlib/fmt#4088).
	- Fixed an unreleased regression in transcoding of surrogate pairs
	  (fmtlib/fmt#4094,
	  fmtlib/fmt#4095). Thanks @phprus.
	- Made `fmt::appender` satisfy `std::output_iterator` concept
	  (fmtlib/fmt#4092,
	  fmtlib/fmt#4093). Thanks @phprus.
	- Made `std::iterator_traits<fmt::appender>` standard-conforming
	  (fmtlib/fmt#4185). Thanks @CaseyCarter.
	- Made it easier to reuse `fmt::formatter<std::string_view>` for types with
	  an implicit conversion to `std::string_view`
	  (fmtlib/fmt#4036,
	  fmtlib/fmt#4055). Thanks @Arghnews.
	- Made it possible to disable `<filesystem>` use via `FMT_CPP_LIB_FILESYSTEM`
	  for compatibility with some video game console SDKs, e.g. Nintendo Switch SDK
	  (fmtlib/fmt#4257,
	  fmtlib/fmt#4258,
	  fmtlib/fmt#4259). Thanks @W4RH4WK and @phprus.
	- Fixed compatibility with platforms that use 80-bit `long double`
	  (fmtlib/fmt#4245,
	  fmtlib/fmt#4246). Thanks @jsirpoma.
	- Added support for UTF-32 code units greater than `0xFFFF` in fill
	  (fmtlib/fmt#4201).
	- Fixed handling of legacy encodings on Windows with GCC
	  (fmtlib/fmt#4162).
	- Made `fmt::to_string` take `fmt::basic_memory_buffer` by const reference
	  (fmtlib/fmt#4261,
	  fmtlib/fmt#4262). Thanks @sascha-devel.
	- Added `fmt::dynamic_format_arg_store::size`
	  (fmtlib/fmt#4270). Thanks @hannes-harnisch.
	- Removed the ability to control locale usage via an undocumented
	  `FMT_STATIC_THOUSANDS_SEPARATOR` in favor of `FMT_USE_LOCALE`.
	- Renamed `FMT_EXCEPTIONS` to `FMT_USE_EXCEPTIONS` for consistency with other
	  similar macros.
	- Improved include directory ordering to reduce the chance of including
	  incorrect headers when using multiple versions of {fmt}
	  (fmtlib/fmt#4116). Thanks @cdzhan.
	- Made it possible to compile a subset of {fmt} without the C++ runtime.
	- Improved documentation and README
	  (fmtlib/fmt#4066,
	  fmtlib/fmt#4117,
	  fmtlib/fmt#4203,
	  fmtlib/fmt#4235). Thanks @zyctree and @nikola-sh.
	- Improved the documentation generator (fmtlib/fmt#4110,
	  fmtlib/fmt#4115). Thanks @rturrado.
	- Improved CI (fmtlib/fmt#4155,
	  fmtlib/fmt#4151). Thanks @phprus.
	- Fixed various warnings and compilation issues
	  (fmtlib/fmt#2708,
	  fmtlib/fmt#4091,
	  fmtlib/fmt#4109,
	  fmtlib/fmt#4113,
	  fmtlib/fmt#4125,
	  fmtlib/fmt#4129,
	  fmtlib/fmt#4130,
	  fmtlib/fmt#4131,
	  fmtlib/fmt#4132,
	  fmtlib/fmt#4133,
	  fmtlib/fmt#4144,
	  fmtlib/fmt#4150,
	  fmtlib/fmt#4158,
	  fmtlib/fmt#4159,
	  fmtlib/fmt#4160,
	  fmtlib/fmt#4170,
	  fmtlib/fmt#4177,
	  fmtlib/fmt#4187,
	  fmtlib/fmt#4188,
	  fmtlib/fmt#4194,
	  fmtlib/fmt#4200,
	  fmtlib/fmt#4205,
	  fmtlib/fmt#4207,
	  fmtlib/fmt#4208,
	  fmtlib/fmt#4210,
	  fmtlib/fmt#4220,
	  fmtlib/fmt#4231,
	  fmtlib/fmt#4232,
	  fmtlib/fmt#4233,
	  fmtlib/fmt#4236,
	  fmtlib/fmt#4267,
	  fmtlib/fmt#4271).
	  Thanks @torsten48, @Arghnews, @tinfoilboy, @aminya, @Ottani, @zeroomega,
	  @c4v4, @kongy, @vinayyadav3016, @sergio-nsk, @phprus and @YexuanXiao.

Signed-off-by: Adolf Belka <[email protected]>
Signed-off-by: Michael Tremer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants