-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
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
#endif This 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
// Check if relaxed C++14 constexpr is supported. | |
// GCC doesn't allow throw in constexpr until version 6 (bug 67371). | |
#ifndef FMT_USE_CONSTEXPR | |
# if (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912 || \ | |
(FMT_GCC_VERSION >= 600 && FMT_CPLUSPLUS >= 201402L)) && \ | |
!FMT_ICC_VERSION && !defined(__NVCC__) | |
# define FMT_USE_CONSTEXPR 1 | |
# else | |
# define FMT_USE_CONSTEXPR 0 | |
# endif | |
#endif | |
#if FMT_USE_CONSTEXPR | |
# define FMT_CONSTEXPR constexpr | |
#else | |
# define FMT_CONSTEXPR | |
#endif |
inline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would it be empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gets defined as empty for some reason:
spdlog/include/spdlog/fmt/bundled/core.h
Line 106 in cedfeeb
# define FMT_CONSTEXPR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it won't matter for spdlog. It can be empty for spdlog as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_CONSTEXPR
is not defined or is defined differently for a given compiler.Ideally, a test could be added of building a
.cu
file using nvcc and add that to CI to prevent nvcc breakages moving forward.