Jinja2Cpp icon indicating copy to clipboard operation
Jinja2Cpp copied to clipboard

non-const fmt format was deprecated and no longer compiles

Open saurik opened this issue 1 year ago • 1 comments

In file included from jinja2cpp/Jinja2Cpp/src/error_info.cpp:3:
In file included from ./vpn/lib/shared/fmt/include/fmt/format.h:56:
./vpn/lib/shared/fmt/include/fmt/base.h:1389:23: error: no matching member function for call to 'format'
    ctx.advance_to(cf.format(*static_cast<qualified_type*>(arg), ctx));
                   ~~~^~~~~~
./vpn/lib/shared/fmt/include/fmt/base.h:1370:21: note: in instantiation of function template specialization 'fmt::detail::value<fmt::context>::format_custom_arg<jinja2::Value, fmt::formatter<jinja2::Value>>' requested here
    custom.format = format_custom_arg<
                    ^
jinja2cpp/Jinja2Cpp/src/error_info.cpp:134:9: note: in instantiation of function template specialization 'fmt::format_to<std::back_insert_iterator<fmt::basic_memory_buffer<char>>, const jinja2::Value &, 0>' requested here
        format_to(std::back_inserter(out), UNIVERSAL_STR("Unexpected exception occurred during template processing. Exception: {}").GetValue<CharT>(), extraParams[0]);
        ^
jinja2cpp/Jinja2Cpp/src/error_info.cpp:267:5: note: in instantiation of function template specialization 'jinja2::RenderErrorInfo<char>' requested here
    RenderErrorInfo(result, *this);
    ^
jinja2cpp/Jinja2Cpp/src/error_info.cpp:105:10: note: candidate function template not viable: 'this' argument has type 'const fmt::formatter<jinja2::Value>', but method is not marked const
    auto format(const jinja2::Value& val, FormatContext& ctx)
         ^
In file included from jinja2cpp/Jinja2Cpp/src/error_info.cpp:3:

This fixes the issue:

diff --git a/src/error_info.cpp b/src/error_info.cpp
index b60cc8e..5cba8f3 100644
--- a/src/error_info.cpp
+++ b/src/error_info.cpp
@@ -102,7 +102,7 @@ struct formatter<jinja2::Value, CharT>
     }
 
     template<typename FormatContext>
-    auto format(const jinja2::Value& val, FormatContext& ctx)
+    auto format(const jinja2::Value& val, FormatContext& ctx) const
     {
         nonstd::visit(ValueRenderer<FormatContext>(&ctx), val.data());
         return fmt::format_to(ctx.out(), UNIVERSAL_STR("").GetValue<CharT>());

saurik avatar Aug 15 '24 07:08 saurik

I was curious why this worked with the default build for Jinja2Cpp, and how long ago this changed in fmt. This was a pretty recent change made in January for 11.x of fmt, but I guess cmake is still shipping 10.x. Per https://github.com/fmtlib/fmt/issues/3447, they made this change to be compatible with std::format (which has this requirement).

saurik avatar Aug 15 '24 23:08 saurik