-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
spdlog 1.8.5 fails to build with libfmt 8.0.0 #1975
Comments
See #1955 (comment) for a fix. For me libfmt 8.0.0 causes a test failure:
|
Is this a duplicate of #1941? |
Compile time format string checking also causes errors around
If you use
|
I made #1976 which fixes some of the build errors, but not everything so I closed it. At the minimum some things with fmt::pad and memory writers also need to be changed. |
Yes, same issue. |
Fixed in latest commit. But I get lots of @vitaut What's the recommended replacement to memory_buf_t buf;
fmt::format_to(buf, fmt, std::forward<Args>(args)...);
details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); |
Only fmt::format_to(std::back_inserter(buf), fmt, std::forward<Args>(args)...); |
Fixed. Thanks @vitaut Now spdlog ships with fmt v8.0 by default! |
🥳 I'm looking forward to a new release version! |
I applied 8bf7186 in part (only the patch to src/fmt.cpp) and v7 headers seem to leak even with Perhaps I misunderstand how that switch is supposed to work, but I was under the impression the bundled fmt headers would be completely ignored in favour of the system ones. |
You need to take latest fmt commit, since it was fixed by fmt after the v8 release. |
See also upstream gabime/spdlog#1975 Signed-off-by: Hank Leininger <[email protected]> Closes: https://bugs.gentoo.org/797394 Package-Manager: Portage-3.0.20, Repoman-3.0.3
See also upstream gabime/spdlog#1975 Signed-off-by: Hank Leininger <[email protected]> Closes: https://bugs.gentoo.org/797394 Package-Manager: Portage-3.0.20, Repoman-3.0.3 Closes: #21413 Signed-off-by: Sam James <[email protected]>
@gabime can you please make a new release of spdlog? |
It is not ready yet. There are compilation problems with cpp 17/20 and with utf support in windows. |
need to fix #1978 |
There's already a fmt v8.0.1 out... |
Any progress on this? I cannot build spdlog for Fedora Rawhide. |
@xvitaly for what is worth, these patches fix the problem on openSUSE Tumbleweed. |
@lgbaldoni It works. Many thanks. |
@vitaut Could you advice on how to use FMT_COMPILE in spdlog? I am having trouble enabling it.
gives me: /home/gabi/spdlog/include/spdlog/logger.h:95:9: error: no matching member function for call to 'log'
log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
^~~
/home/gabi/spdlog/include/spdlog/logger.h:113:9: note: in instantiation of function template specialization 'spdlog::logger::log<FMT_COMPILE_STRING, char const (&)[7]>' requested here
log(level::info, fmt, std::forward<Args>(args)...);
^
/home/gabi/spdlog/include/spdlog/spdlog.h:157:27: note: in instantiation of function template specialization 'spdlog::logger::info<FMT_COMPILE_STRING, char const (&)[7]>' requested here
default_logger_raw()->info(fmt, std::forward<Args>(args)...);
^
/home/gabi/spdlog/example/example.cpp:34:13: note: in instantiation of function template specialization 'spdlog::info<FMT_COMPILE_STRING, char const (&)[7]>' requested here
spdlog::info(FMT_COMPILE("should not compile ? {:d}"), "SDFSDF");
^
/home/gabi/spdlog/include/spdlog/logger.h:87:10: note: candidate function template not viable: no known conversion from 'const FMT_COMPILE_STRING' to 'spdlog::string_view_t' (aka 'basic_string_view<char>') for 3rd argument
void log(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args)
^
/home/gabi/spdlog/include/spdlog/logger.h:148:10: note: candidate function not viable: no known conversion from 'spdlog::source_loc' to 'log_clock::time_point' (aka 'time_point<std::chrono::system_clock, duration<long, ratio<1, 1000000000>>>') for 1st argument
void log(log_clock::time_point log_time, source_loc loc, level::level_enum lvl, string_view_t msg)
^
/home/gabi/spdlog/include/spdlog/logger.h:80:10: note: candidate template ignored: requirement 'fmt::is_compile_string<FMT_COMPILE_STRING>::value' was not satisfied [with FormatString = FMT_COMPILE_STRING]
void log(source_loc loc, level::level_enum lvl, const FormatString &fmt, Args &&...args)
^
/home/gabi/spdlog/include/spdlog/logger.h:183:10: note: candidate function template not viable: requires 3 arguments, but 4 were provided
void log(source_loc loc, level::level_enum lvl, const T &msg)
^
/home/gabi/spdlog/include/spdlog/logger.h:161:10: note: candidate function not viable: requires 3 arguments, but 4 were provided
void log(source_loc loc, level::level_enum lvl, string_view_t msg)
^
/home/gabi/spdlog/include/spdlog/logger.h:143:10: note: candidate function template not viable: requires 3 arguments, but 4 were provided
void log(source_loc loc, level::level_enum lvl, const T &msg)
^
/home/gabi/spdlog/include/spdlog/logger.h:93:10: note: candidate function template not viable: no known conversion from 'spdlog::source_loc' to 'level::level_enum' for 1st argument
void log(level::level_enum lvl, const FormatString &fmt, Args &&...args)
^
/home/gabi/spdlog/include/spdlog/logger.h:174:10: note: candidate function not viable: requires 2 arguments, but 4 were provided
void log(level::level_enum lvl, string_view_t msg)
^
/home/gabi/spdlog/include/spdlog/logger.h:135:10: note: candidate function template not viable: requires 2 arguments, but 4 were provided
void log(level::level_enum lvl, const T &msg) and If I remove |
AFAICS removing |
Unfortunately it doesn't work in spdlog context. I created a branch to reproduce: https://github.com/gabime/spdlog/blob/issue_1975/example/example.cpp @vitaul Any help would be very appreciated. |
Is the repro supposed to give an error? It compiles with clang:
Which compiler and options do you use? |
I see you mention clang 13 and c++20 in one of the previous comment which is kinda close to my setup. |
I expected the line spdlog::info(FMT_COMPILE("Should not compile {:d}"), "hello"); to fail in compile time but it passed. I tried both gcc11 and clang, and got same result. |
AFAICS the problem is in method memory_buf_t buf;
// faster than fmt::format_to(std::back_inserter(buf), fmt, std::forward<Args>(args)...);
fmt::detail::vformat_to(buf, fmt::string_view(fmt), fmt::make_format_args(args...), {}); I don't outright see which overload of which function to use, though. |
I already tried to remove the conversion. Didn’t help. Got compiler errors. |
@mjerabek is correct, the reason why you don't get compile-time checks (or rather format string compilation because that's what fmt::format_to(std::back_inserter(buf), fmt, std::forward<Args>(args)...); instead of spdlog/include/spdlog/logger.h Line 342 in 70d2832
You get compile errors because |
But then it won't compile (in c++20) without always wrapping with FMT_COMPILE: https://godbolt.org/z/35bvsq3cW What I am trying to achieve it to provide the user the option to call info with or without FMT_COMPILE. I tried here https://godbolt.org/z/1xhvrbexn to overload using But that doesn't seem to work either. seems the format string is never marked as As a side note,I thought that fmt enables compile-time format check by default in c++20, but it seems one need to wrap with |
In that case you'll need two overloads, one with format string compilation and one without (https://godbolt.org/z/Msc1cx3jq): #include <fmt/compile.h>
template <
typename S, typename... T,
std::enable_if_t<!std::is_convertible_v<const S&, fmt::format_string<T...>>, int> = 0>
void info(const S& fmt, T&&... args) {
auto buf = fmt::memory_buffer();
fmt::format_to(std::back_inserter(buf), fmt, std::forward<T>(args)...);
}
template <typename... T>
void info(fmt::format_string<T...> fmt, T&&... args) {
auto buf = fmt::memory_buffer();
fmt::format_to(std::back_inserter(buf), fmt, std::forward<T>(args)...);
} |
I might be missing something.. It doesn't compile if wrapped with |
I messed up SFINAE in the example, should be fixed now (I updated the comment). |
Great. Thanks @vitaut. Anyway, seems that under c++20 the format string get compiled anyway (even without wrapping with FMT_COMPILE). Probably by design? |
It will be validated at compile-time but still processed at runtime unless you wrap it in |
According to gabime/spdlog#1975 spdlog will not compile with fmt 8.0.0, that is the version cached in Github Actions Runners. If I confirm that I'll not use spdlog, I can reverse this change. Right now I just want to see if the CI will run all the way.
I'm getting |
I also ran into this issue. This problem is often encountered because it does not know how to convert to the target type. |
Trying to build spdlog 1.8.5 with libfmt 8.0.0 fails with this error:
build.log
The text was updated successfully, but these errors were encountered: