We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Logging using a formatted string does not work under clang.
#include <spdlog/spdlog.h> auto main() -> int { spdlog::error("Some error message without arg"); return 0; }
#include <spdlog/spdlog.h> auto main() -> int { spdlog::error("Some error message with arg: {}", 1); return 0; }
Second example should compile. GCC has no issue with it:
[2025-01-01 12:47:24.988] [error] Some error message without arg: 1
Clang rejects it with this error message:
[build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:334:9: error: call to consteval function 'fmt::basic_format_string<char, const char *, const char *&, int &>::basic_format_string<FMT_COMPILE_STRING, 0>' is not a constant expression [build] 334 | SPDLOG_LOGGER_CATCH(loc) [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:34:46: note: expanded from macro 'SPDLOG_LOGGER_CATCH' [build] 34 | err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \ [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/common.h:55:46: note: expanded from macro 'SPDLOG_FMT_STRING' [build] 55 | #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/format.h:1827:23: note: expanded from macro 'FMT_STRING' [build] 1827 | #define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string, ) [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/format.h:1806:3: note: expanded from macro 'FMT_STRING_IMPL' [build] 1806 | [] { \ [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:80:9: note: in instantiation of function template specialization 'spdlog::logger::log_<int>' requested here [build] 80 | log_(loc, lvl, details::to_string_view(fmt), std::forward<Args>(args)...); [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:85:9: note: in instantiation of function template specialization 'spdlog::logger::log<int>' requested here [build] 85 | log(source_loc{}, lvl, fmt, std::forward<Args>(args)...); [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:150:9: note: in instantiation of function template specialization 'spdlog::logger::log<int>' requested here [build] 150 | log(level::err, fmt, std::forward<Args>(args)...); [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/spdlog.h:178:27: note: in instantiation of function template specialization 'spdlog::logger::error<int>' requested here [build] 178 | default_logger_raw()->error(fmt, std::forward<Args>(args)...); [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/source/main.cpp:5:13: note: in instantiation of function template specialization 'spdlog::error<int>' requested here [build] 5 | spdlog::error("Some error message with arg: {}", 1); [build] | ^ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/base.h:779:54: note: subexpression not valid in a constant expression [build] 779 | format_str_.remove_prefix(detail::to_unsigned(it - begin())); [build] | ~~~^~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/base.h:2761:5: note: in call to 'this->context_.advance_to(&"{} [{}({})]"[1])' [build] 2761 | context_.advance_to(begin); [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/base.h:2756:5: note: in call to 'this->on_format_specs(0, &"{} [{}({})]"[1], &"{} [{}({})]"[1])' [build] 2756 | on_format_specs(id, begin, begin); // Call parse() on empty specs. [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/base.h:2581:5: note: in call to 'handler.on_replacement_field(0, &"{} [{}({})]"[1])' [build] 2581 | handler.on_replacement_field(handler.on_arg_id(), begin); [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/base.h:2613:21: note: in call to 'parse_replacement_field<char, fmt::detail::format_string_checker<char, const char *, const char *, int> &>(&"{} [{}({})]"[1], &"{} [{}({})]"[11], checker(s))' [build] 2613 | begin = p = parse_replacement_field(p - 1, end, handler); [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/base.h:2884:7: note: in call to 'parse_format_string<true, char, fmt::detail::format_string_checker<char, const char *, const char *, int>>({&"{} [{}({})]"[0], 11}, checker(s))' [build] 2884 | detail::parse_format_string<true>(str_, checker(s)); [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:334:9: note: in call to 'basic_format_string<FMT_COMPILE_STRING, 0>([] { [build] struct FMT_COMPILE_STRING : fmt::detail::compile_string { [build] using char_type [[maybe_unused]] = fmt::remove_cvref_t<decltype("{} [{}({})]"[0])>; [build] }; [build] return FMT_COMPILE_STRING(); [build] }())' [build] 334 | SPDLOG_LOGGER_CATCH(loc) [build] | ^~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/logger.h:34:46: note: expanded from macro 'SPDLOG_LOGGER_CATCH' [build] 34 | err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \ [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/spdlog/common.h:55:46: note: expanded from macro 'SPDLOG_FMT_STRING' [build] 55 | #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/format.h:1827:23: note: expanded from macro 'FMT_STRING' [build] 1827 | #define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string, ) [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] /media/houssam/OS/Users/doria/Documents/Cxx/hsm/build/dev/vcpkg_installed/x64-linux/include/fmt/format.h:1806:3: note: expanded from macro 'FMT_STRING_IMPL' [build] 1806 | [] { \ [build] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1807 | /* Use the hidden visibility as a workaround for a GCC bug (#1973). */ \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1808 | /* Use a macro-like name to avoid shadowing warnings. */ \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1809 | struct FMT_VISIBILITY("hidden") FMT_COMPILE_STRING : base { \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1810 | using char_type FMT_MAYBE_UNUSED = fmt::remove_cvref_t<decltype(s[0])>; \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1811 | FMT_MAYBE_UNUSED FMT_CONSTEXPR explicit \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1812 | operator fmt::basic_string_view<char_type>() const { \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1813 | return fmt::detail_exported::compile_string_to_view<char_type>(s); \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1814 | } \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1815 | }; \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1816 | return FMT_COMPILE_STRING(); \ [build] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [build] 1817 | }() [build] | ~~~ [build] 1 error generated.
The text was updated successfully, but these errors were encountered:
This is fmt issue and already fixed fmtlib/fmt#4177
Sorry, something went wrong.
I see. Thanks for the info!
No branches or pull requests
Description
Logging using a formatted string does not work under clang.
How to reproduce
OK
Not OK
Expected behaviour
Second example should compile. GCC has no issue with it:
Clang rejects it with this error message:
Configuration
The text was updated successfully, but these errors were encountered: