spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

#define SPDLOG_LEVEL_NAMES with external FMT doesn't compile, starting from libfmt11.

Open Lord-Kamina opened this issue 1 year ago • 5 comments

This came up macOS/apple clang:

In file included from /opt/local/include/spdlog/common.h:410:
/opt/local/include/spdlog/common-inl.h:19:26: error: constexpr variable 'level_string_views' must be initialized by a constant expression
    static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
                         ^                    ~~~~~~~~~~~~~~~~~~
/opt/local/include/spdlog/common-inl.h:19:47: note: non-constexpr constructor 'basic_string_view' cannot be used in a constant expression
    static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
                                              ^
/Users/Koji/performous/game/log.hh:11:30: note: expanded from macro 'SPDLOG_LEVEL_NAMES'
#define SPDLOG_LEVEL_NAMES { "TRACE", "DEBUG", "INFO", "NOTICE", "WARNING", "ERROR", "OFF" }
                             ^
/opt/local/include/libfmt11/fmt/base.h:536:3: note: declared here
  basic_string_view(const Char* s)
  ^

Removing the constexpr from static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; makes it compile, but I don't think this is really the correct fix?

Lord-Kamina avatar Oct 29 '24 18:10 Lord-Kamina

This is working, and at least is a better work-around IMO:

#include <string_view>
using namespace std::string_view_literals;
#define SPDLOG_LEVEL_NAMES { "TRACE"sv, "DEBUG"sv, "INFO"sv, "NOTICE"sv, "WARNING"sv, "ERROR"sv, "OFF"sv }

Lord-Kamina avatar Oct 29 '24 19:10 Lord-Kamina

PR is welcome. Note that the “sv” literal is c++17 while spdlog should support 11

gabime avatar Oct 29 '24 20:10 gabime

PR is welcome. Note that the “sv” literal is c++17 while spdlog should support 11

I would open a PR, but I don't really know what the best approach is for the majority of people.

Lord-Kamina avatar Oct 29 '24 20:10 Lord-Kamina

PR is welcome. Note that the “sv” literal is c++17 while spdlog should support 11

I was thinking again on this and realized that this would likely not really be an issue, because the problem only presents when level_string_views[] is declared constexpr and that is gated under a check for c++17 already.

So, most likely for now at least the only thing you really need to change is documenting this option, which could likely be done in the same tweakme header

Lord-Kamina avatar Oct 30 '24 14:10 Lord-Kamina

PR is welcome. Note that the “sv” literal is c++17 while spdlog should support 11

I was thinking again on this and realized that this would likely not really be an issue, because the problem only presents when level_string_views[] is declared constexpr and that is gated under a check for c++17 already.

So, most likely for now at least the only thing you really need to change is documenting this option, which could likely be done in the same tweakme header

I encountered this issue while compiling the project using C++ 17, and after switching the C++ version to 14 or 20, the compilation was successful.

F1F88 avatar Nov 16 '24 05:11 F1F88