fmtlib / fmt

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

[Solved, me being stupid] Upgrade from v100101 to v100201 gives many errors #3908

Closed SanderBouwhuis closed 3 months ago

SanderBouwhuis commented 3 months ago

Compiler : Microsoft Visual Studio Community 2022 (64-bit) - Version 17.9.5 FmtLib : v100201

I have been using v100101 for a while now. I decided to upgrade the library to the current release version (v100201). But, when I recompile my solution, I get many errors.

This is the line which works with v100101 and fails with v100201:

  // Show the current cumulative time (including stack usage)
  wstrMsg = fmt::format(FMT_STRING(L"  <- [{}]{:02}:{:02}:{:02}.{:07} ({}{:.7f}) : stack{:*<{}} = {}  '{}'{}\n"),
    time.Hour(), time.Minute(), time.Second(), time.NanoSecond()/100,
    Dbl_IsBigger(dCumulative, 10.0) ? L"^^^" : (Dbl_IsBigger(dCumulative, 5.0) ? L"^^" : (Dbl_IsBigger(dCumulative, 1.0) ? L"^" : L"")),
    dCumulative,
    L"", stackInfo.i64StackUsed / 100'000, stackInfo.i64StackUsed,
    m_wstrDescription.GetString(),
    wstrExtraDesc.GetString());

Here are the first few errors:

Q:\Dms v9.1.0 Head\Classes\CProfile.cpp(203,25): error C7595: 'fmt::v10::basic_format_string<wchar_t,unsigned char,unsigned char,unsigned char,int,const wchar_t *,double &,const wchar_t (&)[1],__int64,int64 &,const wchar_t *,const wchar_t *>::basic_format_string': call to immediate function is not a constant expression
(compiling source file '/CProfile.cpp')
Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2384,27):
failure was caused by call of undefined function or one not declared 'constexpr'
Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2384,27):
see usage of 'fmt::v10::detail::throw_format_error'
Q:\Dms v9.1.0 Head\Classes\CProfile.cpp(203,25):
the call stack of the evaluation (the oldest call first) is
    Q:\Dms v9.1.0 Head\Classes\CProfile.cpp(203,25):
    while evaluating function 'fmt::v10::basic_format_string<wchar_t,unsigned char,unsigned char,unsigned char,int,const wchar_t *,double &,const wchar_t (&)[1],__int64,int64 &,const wchar_t *,const wchar_t *>::basic_format_string<CProfile::ShowCumulativeTime::<lambda_2>::()::FMT_COMPILE_STRING,0>(const S &)'
        with
        [
            S=CProfile::ShowCumulativeTime::<lambda_2>::()::FMT_COMPILE_STRING
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2787,40):
    while evaluating function 'void fmt::v10::detail::parse_format_string<true,wchar_t,checker>(fmt::v10::basic_string_view<wchar_t>,Handler &&)'
        with
        [
            Handler=checker
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2568,36):
    while evaluating function 'const Char *fmt::v10::detail::parse_replacement_field<wchar_t,Handler&>(const Char *,const Char *,fmt::v10::detail::format_string_checker<Char,unsigned char,unsigned char,unsigned char,int,const wchar_t *,double,wchar_t [1],__int64,__int64,const wchar_t *,const wchar_t *>&)'
        with
        [
            Char=wchar_t,
            Handler=checker
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2512,38):
    while evaluating function 'const Char *fmt::v10::detail::format_string_checker<Char,unsigned char,unsigned char,unsigned char,int,const wchar_t *,double,wchar_t [1],__int64,__int64,const wchar_t *,const wchar_t *>::on_format_specs(int,const Char *,const Char *)'
        with
        [
            Char=wchar_t
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2684,55):
    while evaluating function 'const Char *fmt::v10::detail::parse_format_specs<const wchar_t*,fmt::v10::detail::compile_parse_context<Char>>(ParseContext &)'
        with
        [
            Char=wchar_t,
            ParseContext=fmt::v10::detail::compile_parse_context<wchar_t>
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2591,53):
    while evaluating function 'const Char *fmt::v10::formatter<mapped_type,Char,void>::parse<ParseContext>(ParseContext &)'
        with
        [
            Char=char_type,
            ParseContext=fmt::v10::detail::compile_parse_context<wchar_t>
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2745,35):
    while evaluating function 'const Char *fmt::v10::detail::parse_format_specs<T>(const Char *,const Char *,fmt::v10::detail::dynamic_format_specs<Char> &,fmt::v10::basic_format_parse_context<Char> &,fmt::v10::detail::type)'
        with
        [
            Char=wchar_t,
            T=wchar_t
        ]
    Q:\Dms v9.1.0 Head\Classes\Fmt\core.h(2384,27):
    while evaluating function 'void fmt::v10::detail::throw_format_error(const char *)'

Apparently, the problem is that there is a 'call to immediate function is not a constant expression'. Can someone explain what has changed in FmtLib which causes my code to no longer compile?

mwinterb commented 3 months ago

(I think...) you're passing 11 parameters but have 12 substitution fields. From the beginning of your format string: " <- [{}]{:02}:{:02}:{:02}.{:07}", the first parameters are: time.Hour(), time.Minute(), time.Second(), time.NanoSecond()/100, which seems like you're missing the parameter for [{}].

SanderBouwhuis commented 3 months ago

@mwinterb I am an idiot. I was in the process of making some changes when I thought it would be a good idea to update FMTLIB. I completely forgot I already changed the FMT_STRING.

Regardless, the error message is very confusing.