Skip to content

non-const fmt format was deprecated and no longer compiles #257

Description

@saurik
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>());

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions