[libcxx-dev] How to check for a feature-test macro
Marshall Clow via libcxx-dev
libcxx-dev at lists.llvm.org
Tue Dec 4 19:34:48 PST 2018
In the tests, we have the following usage:
#if TEST_STD_VER > 14
# if !defined(__cpp_lib_filesystem)
# error "__cpp_lib_filesystem is not defined"
# elif __cpp_lib_filesystem < 201703L
# error "__cpp_lib_filesystem has an invalid value"
# endif
#endif
I submit that that's non-portable, because some standard libraries may not
implement all the features (that's the point of the feature-test macro),
and this test should not fail.
In D55308, I am using the following form:
#if TEST_STD_VER > 17
LIBCPP_ASSERT(IS_DEFINED(__cpp_lib_char8_t)); // libc++ implements this
# if defined(__cpp_lib_char8_t)
# if __cpp_lib_char8_t < 201811L
# error "__cpp_lib_char8_t has an invalid value"
# endif
# endif
#endif
Basically it (unconditionally) checks that if the macro is defined, then it
has a sane value.
Additionally, since we know that libc++ defines this, we check that.
An alternate formulation - w/o the `IS_DEFINED` trickery.
#if TEST_STD_VER > 17
# if !defined(__cpp_lib_char8_t)
LIBCPP_STATIC_ASSERT(false, "__cpp_lib_char8_t is not defined");
# else
# if __cpp_lib_char8_t < 201811L
# error "__cpp_lib_char8_t has an invalid value"
# endif
# endif
#endif
Comments welcome.
-- Marshall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20181204/5d4a4e38/attachment.html>
More information about the libcxx-dev
mailing list