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
Fix XXH_UNREACHABLE
feature test for C++23 and remove for C23 #791
#792
Conversation
xxhash.h
Outdated
* additional case: | ||
* | ||
* ``` | ||
* #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) |
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 presume you meant __STDC_VERSION__ > 202310L
in this example
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.
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.
Since C23 didn't set actual __STDC_VERSION__
yet (right?), I think we can express C23 as "beyond/greater than C17 (> 201710L
)" for now.
It must be fixed after the comittee and compilers set official __STDC_VERSION__
though.
So, adding TODO
or note
comment would be nice to reminder.
Thank you @goldsteinn for quick fix! Since this PR drops support for C23, below is not a review. Just a note for (possible) future issues/improvements. According to "7.21 Common definitions <stddef.h>" in n3054.pdf, #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= XXH_C23_VN)
/* C23 and future versions have unreachable() macro */
# include <stddef.h>
# if defined(unreachable)
# define XXH_UNREACHABLE() unreachable()
# endif
#endif If we can allow cumbersome definition, it may look like this: /* C/C++ standard definitions */
#if !defined(XXH_UNREACHABLE)
# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= XXH_C23_VN)
/* C23 and future versions have unreachable() macro */
# include <stddef.h> /* unreachable() */
# if defined(unreachable)
# define XXH_UNREACHABLE() unreachable()
# endif
# elif defined(__cpp_lib_unreachable) && (__cpp_lib_unreachable >= 202202L)
/* C++23 and future versions have std::unreachable() */
# include <utility> /* std::unreachable() */
# define XXH_UNREACHABLE() std::unreachable()
# endif
#endif
/* Compiler specific definitions */
#if !defined(XXH_UNREACHABLE)
# if XXH_HAS_BUILTIN(__builtin_unreachable)
# define XXH_UNREACHABLE() __builtin_unreachable()
# elif defined(_MSC_VER)
# define XXH_UNREACHABLE() __assume(0)
# endif
#endif
/* Fallback */
#if !defined(XXH_UNREACHABLE)
# define XXH_UNREACHABLE()
#endif |
Thank you for the fix! One more thing:
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h> None of which include I would propose adding a #if __has_include(<version>)
#include <version>
#endif Before checking for The |
Hmm, so once its actually working there seems to be an issue with the Not too hard to fix by closing the |
…973#791 gcc11/12 don't support `std::unreachable()` in there `-std=c++23` build. A more reliable check is: ``` ``` so use that. A similiar issue may occur for C23 `unreachable()` so just remove it on the basis that if a compiler doesn't currently support some builtin for unreachable/assume its very likely not using it in analysis so we are probably not missing much (if anything) leaving it out.
gcc11/12 don't support
std::unreachable()
in there-std=c++23
build.A more reliable check is:
so use that.
A similiar issue may occur for C23
unreachable()
so just remove it on the basis that if a compiler doesn't currently support some builtin for unreachable/assume its very likely not using it in analysis so we are probably not missing much (if anything) leaving it out.