Match SPDLOG_CONSTEXPR_FUNC to FMT_CONSTEXPR#2901
Conversation
fix the issue where constexpr function in spdlog may call non-constexpr function in the bundled fmt because FMT_USE_CONSTEXPR is not defined.
…t explaining the constexpr check
|
An alternative approach that might work here is to reuse #ifdef FMT_CONSTEXPR
#define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR
#else
#if __cplusplus >= 201402L
#define SPDLOG_CONSTEXPR_FUNC constexpr
#else
#define SPDLOG_CONSTEXPR_FUNC inline
#endif
#endifThis may be friendlier to when we're using |
Agreed. Seems cleaner and to the point (use same constexpr as fmt). |
| #if FMT_USE_CONSTEXPR | ||
| #define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR | ||
| #else | ||
| #define SPDLOG_CONSTEXPR_FUNC inline | ||
| #define SPDLOG_CONSTEXPR_FUNC inline |
There was a problem hiding this comment.
I needed to change this slightly to maintain the current behavior. If fmt determines it can't use constexpr then it defines FMT_CONSTEXPR as empty
spdlog/include/spdlog/fmt/bundled/core.h
Lines 92 to 107 in cedfeeb
inline
There was a problem hiding this comment.
We could probably use some preprocessor magic to detect when FMT_CONSTEXPR is empty and use inline instead in those situations, but that adds some non-trivial complexity.
There was a problem hiding this comment.
It gets defined as empty for some reason:
spdlog/include/spdlog/fmt/bundled/core.h
Line 106 in cedfeeb
There was a problem hiding this comment.
I think it won't matter for spdlog. It can be empty for spdlog as well.
There was a problem hiding this comment.
Updated based on that
|
Looks like without the inline in C++11 (in C++14 and newer it would be constexpr) we hit some ODR violations from the header being included in multiple translation units that then get linked into a single artifact. |
|
So I guess we need to use your first suggestion after all. |
… it's defined" This reverts commit 1897f70.
|
Reverted the change where I think this should be good to go. Thanks for your review and feedback @gabime! |
|
Thanks @kkraus14 |
Fixes #2856.
PR based on #2858 and #2859.
Fixes the issue where a constexpr function in spdlog may call a non-constexpr function in fmt because
FMT_CONSTEXPRis not defined or is defined differently for a given compiler.Ideally, a test could be added of building a
.cufile using nvcc and add that to CI to prevent nvcc breakages moving forward.