fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
20.78k stars 2.5k forks source link

MSVC 19.35 error C2794 #4091

Closed sergiud closed 3 months ago

sergiud commented 3 months ago

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

https://github.com/fmtlib/fmt/blob/0c9fce2ffefecfdce794e1859584e25877b7b592/test/color-test.cc#L53-L55

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 commented 3 months ago

Repro: https://www.godbolt.org/z/rEheMxx9a

vitaut commented 3 months ago

Should be fixed in https://github.com/fmtlib/fmt/commit/6e462b89aa22fd5f737ed162d0150e145ccb1914.

asdiujvaosidujdposiadjapoij commented 2 months ago

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 commented 2 months ago

@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 commented 2 months ago

Please provide a godbolt repro similar to the one above.

Zhaojun-Liu commented 2 months ago

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 commented 2 months ago

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

vitaut commented 2 months ago

Thanks for the repro. Fixed in https://github.com/fmtlib/fmt/commit/50aac2ac92cd3defe2429110717a35f345691a36.