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

MSVC 19.35 error C2794 #4091

Closed
sergiud opened this issue Jul 29, 2024 · 8 comments
Closed

MSVC 19.35 error C2794 #4091

sergiud opened this issue Jul 29, 2024 · 8 comments

Comments

@sergiud
Copy link
Contributor

sergiud commented Jul 29, 2024

With fmt 11.0.2 I'm seeing the following compiler error in color-test.cc that is seemingly caused by this check

fmt/test/color-test.cc

Lines 53 to 55 in 0c9fce2

EXPECT_EQ(fmt::format("{}{}", fmt::styled("red", fg(fmt::color::red)),
fmt::styled("bold", fmt::emphasis::bold)),
"\x1b[38;2;255;000;000mred\x1b[0m\x1b[1mbold\x1b[0m");

FAILED: test/CMakeFiles/color-test.dir/color-test.cc.obj 
C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1435~1.322\bin\Hostx64\x64\cl.exe  /nologo /TP -DFMT_SHARED -DGTEST_HAS_STD_WSTRING=1 -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING=1 -ID:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include -external:ID:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\test\gtest\. -external:W0 /utf-8  /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -Zi /utf-8 /showIncludes /Fotest\CMakeFiles\color-test.dir\color-test.cc.obj /Fdtest\CMakeFiles\color-test.dir\ /FS -c D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\test\color-test.cc
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(838): error C2794: 'reference': is not a member of any direct or indirect base class of 'std::iterator_traits<fmt::v11::appender>'
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4127): note: see reference to alias template instantiation 'std::_Iter_ref_t<_Iter>' being compiled
        with
        [
            _Iter=fmt::v11::appender
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4188): note: see reference to variable template 'const bool _Iterator_is_volatile<fmt::v11::basic_appender<char> >' being compiled
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4297): note: see reference to alias template instantiation 'std::_Sent_copy_cat<_InIt,_Sent,_OutIt>' being compiled
        with
        [
            _InIt=const char *,
            _Sent=const char *,
            _OutIt=fmt::v11::appender
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4329): note: see reference to function template instantiation '_OutIt std::_Copy_unchecked<_Iter,_Iter,_OutIt>(_InIt,_Sent,_OutIt)' being compiled
        with
        [
            _OutIt=fmt::v11::appender,
            _Iter=const char *,
            _InIt=const char *,
            _Sent=const char *
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt/color.h(570): note: see reference to function template instantiation '_OutIt std::copy<const Char*,fmt::v11::appender>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=fmt::v11::appender,
            Char=char,
            _InIt=const char *
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(1402): note: see reference to function template instantiation 'fmt::v11::appender fmt::v11::formatter<U,char,void>::format<Context>(const fmt::v11::detail::styled_arg<char [4]> &,FormatContext &) const' being compiled
        with
        [
            U=fmt::v11::detail::styled_arg<char [4]>,
            Context=fmt::v11::format_context,
            FormatContext=fmt::v11::format_context
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(1402): note: see reference to function template instantiation 'fmt::v11::appender fmt::v11::formatter<U,char,void>::format<Context>(const fmt::v11::detail::styled_arg<char [4]> &,FormatContext &) const' being compiled
        with
        [
            U=fmt::v11::detail::styled_arg<char [4]>,
            Context=fmt::v11::format_context,
            FormatContext=fmt::v11::format_context
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(1384): note: see reference to function template instantiation 'void fmt::v11::detail::value<Context>::format_custom_arg<value_type,fmt::v11::formatter<U,char,void>>(void *,fmt::v11::context::parse_context_type &,Context &)' being compiled
        with
        [
            Context=fmt::v11::context,
            U=fmt::v11::detail::styled_arg<char [4]>
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(1383): note: see reference to function template instantiation 'void fmt::v11::detail::value<Context>::format_custom_arg<value_type,fmt::v11::formatter<U,char,void>>(void *,fmt::v11::context::parse_context_type &,Context &)' being compiled
        with
        [
            Context=fmt::v11::context,
            U=fmt::v11::detail::styled_arg<char [4]>
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(1647): note: see reference to function template instantiation 'fmt::v11::detail::value<Context>::value<T>(T &)' being compiled
        with
        [
            Context=fmt::v11::context,
            T=fmt::v11::detail::styled_arg<char [4]>
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(1647): note: see reference to function template instantiation 'fmt::v11::detail::value<Context>::value<T>(T &)' being compiled
        with
        [
            Context=fmt::v11::context,
            T=fmt::v11::detail::styled_arg<char [4]>
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\base.h(2019): note: see reference to function template instantiation 'fmt::v11::detail::value<Context> fmt::v11::detail::make_arg<true,Context,fmt::v11::detail::styled_arg<char [4]>,0>(T &)' being compiled
        with
        [
            Context=fmt::v11::context,
            T=fmt::v11::detail::styled_arg<char [4]>
        ]
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\include\fmt\format.h(4365): note: see reference to function template instantiation 'fmt::v11::detail::format_arg_store<fmt::v11::format_context,2,0,255> fmt::v11::make_format_args<fmt::v11::format_context,fmt::v11::detail::styled_arg<char [4]>,fmt::v11::detail::styled_arg<char [5]>,2,0,255,0>(fmt::v11::detail::styled_arg<char [4]> &,fmt::v11::detail::styled_arg<char [5]> &)' being compiled
D:\foo_fmt-11.0.2\build-winpc-x64-msvc2022\fmt-prefix\src\fmt\test\color-test.cc(55): note: see reference to function template instantiation 'std::string fmt::v11::format<fmt::v11::detail::styled_arg<char [4]>,fmt::v11::detail::styled_arg<char [5]>>(fmt::v11::basic_format_string<char,fmt::v11::detail::styled_arg<char [4]>,fmt::v11::detail::styled_arg<char [5]>>,fmt::v11::detail::styled_arg<char [4]> &&,fmt::v11::detail::styled_arg<char [5]> &&)' being compiled
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4127): error C2938: 'std::_Iter_ref_t' : Failed to specialize alias template
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4127): error C2062: type 'unknown-type' unexpected
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4188): error C3376: 'std::_Iterator_is_volatile': only static data member templates are allowed
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4291): error C2976: 'std::_Iter_copy_cat': too few template arguments
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4190): note: see declaration of 'std::_Iter_copy_cat'
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4297): error C2039: '_Bitcopy_assignable': is not a member of '`global namespace''
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4297): error C2059: syntax error: ')'
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xutility(4297): error C2143: syntax error: missing ';' before '{'

I cannot provide a reproducer on Goldbolt since its MSVC installation cannot currently find the fmt includes.

@vitaut
Copy link
Contributor

vitaut commented Jul 29, 2024

@vitaut
Copy link
Contributor

vitaut commented Jul 29, 2024

Should be fixed in 6e462b8.

@asdiujvaosidujdposiadjapoij

I just cloned and tried to compile in Windows 11, with Visual Studio Community 2022 17.11.2, and I have the same errors.

@Zhaojun-Liu
Copy link
Contributor

@vitaut I also encountered this issue with building the latest commit b52fb98 on Windows with VS17.11.2. Error info as follows:

"C:\gitP\fmtlib\fmt\build_amd64\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\gitP\fmtlib\fmt\build_amd64\test\chrono-test.vcxproj" (default target) (16) ->
 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\include\xutility(1187,54): error C2794: 'reference': is not a member of any direct or indirect base class of 'std::iterator_traits<fmt::v11::appender>' [C:\gitP\fmtlib\fmt\build_amd64\test\chrono-test.vcxproj]
 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\include\xutility(4546,73): error C2938: 'std::_Iter_ref_t' : Failed to specialize alias template [C:\gitP\fmtlib\fmt\build_amd64\test\chrono-test.vcxproj]
 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\include\xutility(4546,40): error C2062: type 'unknown-type' unexpected [C:\gitP\fmtlib\fmt\build_amd64\test\chrono-test.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\include\xutility(4607,29): error C3376: 'std::_Iterator_is_volatile': only static data member templates are allowed [C:\gitP\fmtlib\fmt\build_amd64\test\chrono-test.vcxproj]

@vitaut
Copy link
Contributor

vitaut commented Sep 13, 2024

Please provide a godbolt repro similar to the one above.

@Zhaojun-Liu
Copy link
Contributor

Please provide a godbolt repro similar to the one above.

I tried to extract all the source files used, you can follow the steps below to reproduce.
Repro steps:

  1. download the fmt.zip and unzip it.
  2. open VS2022 x64 Native Tools command.
  3. cd \fmt\test
  4. cl.exe /c /I..\include /Igtest /EHsc /utf-8 "chrono-test.cc"
    fmt.zip

@KKhanhH
Copy link
Contributor

KKhanhH commented Sep 14, 2024

@vitaut I'm also getting the same issue, here's the godbolt repro https://www.godbolt.org/z/obfW8TWPG

@vitaut
Copy link
Contributor

vitaut commented Sep 14, 2024

Thanks for the repro. Fixed in 50aac2a.

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

5 participants