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

spdlog and fmt::join #1757

Closed
bouda1 opened this issue Dec 3, 2020 · 5 comments
Closed

spdlog and fmt::join #1757

bouda1 opened this issue Dec 3, 2020 · 5 comments

Comments

@bouda1
Copy link

bouda1 commented Dec 3, 2020

Hi,

I have made the upgrade to spdlog 1.8.1 with {fmt} 7.1.2. Previously, I was using {fmt} 6.2.0 and spdlog 1.5.0.

Sometimes, I have lines like the following one:

log->debug("message {}", fmt::join(v, ", "));
where v is for example a vector of strings.

This line does not compile anymore. The workaround I found is to call fmt::format like this:
log->debug("message {}", fmt::format("{}", fmt::join(v, ", ")));

It does not look great...
Maybe this is not a real issue and you recommend to do otherwise.
What would you suggest?
Thank you.

@tt4g
Copy link
Contributor

tt4g commented Dec 3, 2020

There are issues that may be related: fmtlib/fmt#2040

EDIT: Can use fmt 7.x? The version of fmt bundled by spdlog 1.8.1 is 7.0.3.

@bouda1
Copy link
Author

bouda1 commented Dec 7, 2020

OK, thank you.

@gabime gabime closed this as completed Dec 7, 2020
@lacc97
Copy link

lacc97 commented Dec 10, 2020

I'm having a similar issue which I don't think is related to the fmtlib bug. I'm using spdlog-1.8.1 and external fmtlib-7.1.3 with gcc-10.2.0 on Gentoo.

When compiling the following minimal example,

#include <fmt/format.h>
#include <spdlog/spdlog.h>

int main() {
  int foo[] = {1, 2, 3};
  spdlog::info("[{}]", fmt::join(foo, ", "));
}

gcc fails with

In file included from /usr/include/fmt/format.h:44,
                 from test.cpp:1:
/usr/include/fmt/core.h: In instantiation of ‘fmt::v7::format_arg_store<fmt::v7::basic_format_context<fmt::v7::detail::buffer_appender<Char>, Char>, fmt::v7::remove_reference_t<Args>...> fmt::v7::make_args_checked(const S&, fmt::v7::remove_reference_t<Args>& ...) [with Args = {const fmt::v7::arg_join<int*, int*, char>&}; S = fmt::v7::basic_string_view<char>; Char = char]’:
/usr/include/fmt/format.h:3820:54:   required from ‘typename fmt::v7::buffer_context<Char>::iterator fmt::v7::format_to(fmt::v7::basic_memory_buffer<Char, SIZE>&, const S&, Args&& ...) [with S = fmt::v7::basic_string_view<char>; Args = {const fmt::v7::arg_join<int*, int*, char>&}; long unsigned int SIZE = 250; Char = char; typename fmt::v7::buffer_context<Char>::iterator = fmt::v7::detail::buffer_appender<char>]’
/usr/include/spdlog/logger.h:340:27:   required from ‘void spdlog::logger::log_(spdlog::source_loc, spdlog::level::level_enum, const FormatString&, const Args& ...) [with FormatString = fmt::v7::basic_string_view<char>; Args = {fmt::v7::arg_join<int*, int*, char>}]’
/usr/include/spdlog/logger.h:87:13:   required from ‘void spdlog::logger::log(spdlog::source_loc, spdlog::level::level_enum, spdlog::string_view_t, const Args& ...) [with Args = {fmt::v7::arg_join<int*, int*, char>}; spdlog::string_view_t = fmt::v7::basic_string_view<char>]’
/usr/include/spdlog/logger.h:93:12:   required from ‘void spdlog::logger::log(spdlog::level::level_enum, const FormatString&, const Args& ...) [with FormatString = char [5]; Args = {fmt::v7::arg_join<int*, int*, char>}]’
/usr/include/spdlog/logger.h:111:12:   required from ‘void spdlog::logger::info(const FormatString&, const Args& ...) [with FormatString = char [5]; Args = {fmt::v7::arg_join<int*, int*, char>}]’
/usr/include/spdlog/spdlog.h:157:31:   required from ‘void spdlog::info(const FormatString&, const Args& ...) [with FormatString = char [5]; Args = {fmt::v7::arg_join<int*, int*, char>}]’
test.cpp:6:44:   required from here
/usr/include/fmt/core.h:1623:53: error: static assertion failed: passing views as lvalues is disallowed
 1621 |       detail::count<(
      |       ~~~~~~~~~~~~~~~                                
 1622 |               std::is_base_of<detail::view, remove_reference_t<Args>>::value &&
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1623 |               std::is_reference<Args>::value)...>() == 0,
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~

Even cherrypicking the fix for the fmtlib bug doesn't fix this, so that's why I don't think it's related.

@lacc97
Copy link

lacc97 commented Dec 10, 2020

Issue seems to be that when calling fmt::format_to from spdlog::logger::log_, the Args type goes from {fmt::v7::arg_join<int*, int*, char>} to {const fmt::v7::arg_join<int*, int*, char>&}, so it may be a problem with forwarding parameters. Not sure how to fix it though.

@lacc97
Copy link

lacc97 commented Dec 10, 2020

Just realised my issue got fixed with #1726.

bachittle pushed a commit to bachittle/spdlog that referenced this issue Dec 22, 2022
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

4 participants