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

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

Open
Lord-Kamina opened this issue Oct 29, 2024 · 4 comments

Comments

@Lord-Kamina
Copy link

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 Lord-Kamina changed the title #define SPDLOG_LEVEL_NAMES with external FMT, starting from libfmt11. #define SPDLOG_LEVEL_NAMES with external FMT doesn't compile, starting from libfmt11. Oct 29, 2024
@Lord-Kamina
Copy link
Author

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 }

@gabime
Copy link
Owner

gabime commented Oct 29, 2024

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

@Lord-Kamina
Copy link
Author

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

Lord-Kamina commented Oct 30, 2024

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

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

2 participants