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

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

Open
saurik opened this issue Aug 15, 2024 · 1 comment
Open

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

saurik opened this issue Aug 15, 2024 · 1 comment

Comments

@saurik
Copy link

saurik commented Aug 15, 2024

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
Copy link
Author

saurik commented Aug 15, 2024

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 fmtlib/fmt#3447, they made this change to be compatible with std::format (which has this requirement).

@saurik saurik changed the title non-const fmt format was deprecated long ago and no longer compiles non-const fmt format was deprecated and no longer compiles Aug 15, 2024
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

1 participant