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 · 5 comments · May be fixed by #3291
Open

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

Lord-Kamina opened this issue Oct 29, 2024 · 5 comments · May be fixed by #3291

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

@F1F88
Copy link
Contributor

F1F88 commented Nov 16, 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

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 added a commit to F1F88/sm-ext-log4sp that referenced this issue Nov 16, 2024
* See: gabime/spdlog#3233
* tweakme.h:107:88: error: call to non-‘constexpr’ function
* include/spdlog/common-inl.h:19:47: note: in expansion of macro ‘SPDLOG_LEVEL_NAMES’
F1F88 added a commit to F1F88/sm-ext-log4sp that referenced this issue Nov 16, 2024
* See: gabime/spdlog#3233
* tweakme.h:107:88: error: call to non-‘constexpr’ function
* include/spdlog/common-inl.h:19:47: note: in expansion of macro ‘SPDLOG_LEVEL_NAMES’
F1F88 added a commit to F1F88/sm-ext-log4sp that referenced this issue Nov 16, 2024
* See: gabime/spdlog#3233

* error 1:
    * tweakme.h:107:88: error: call to non-‘constexpr’ function
    * include/spdlog/common-inl.h:19:47: note: in expansion of macro ‘SPDLOG_LEVEL_NAMES’
* error 2:
    * the value of ‘leftAlign’ is not usable in a constant expression
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

Successfully merging a pull request may close this issue.

3 participants