C++26 freestanding feature-test macros#3837
Conversation
Apply them to older modes when the corresponding feature/header is available.
|
CC-ing @ben-craig. |
You may want to drop a static assert somewhere checking
The standard doesn't really talk about older modes, and I didn't do anything to audit which modes / standards would make sense. Sure, all the stuff in C++03 from the |
The value
I don't actually know what |
|
From the paper:
Example... #if (__STDC_HOSTED__ || \
(defined(__cpp_lib_freestanding_feature_test_macros) && \
__cpp_lib_freestanding_feature_test_macros >= 202112))
#define TRUTHFUL_MACROS 1
#else
#define TRUTHFUL_MACROS 0
#endif
// see if filesystem happens to be supported on this possibly freestanding environment
#if TRUTHFUL_MACROS && defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
// hosted and freestanding extension success path
#else
// fallback path
#endifSo that macro should only be important for actual freestanding implementations. |
|
Because these feature-test macros are essentially defined unconditionally, we can accept this as a special exception to our "no C++26 PRs yet" policy. |
|
Thanks! After fixing a copy-paste typo, looks perfect! 😻 |
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
|
Thanks for implementing all of these feature-test macros! 🎉 ⚙️ 🚀 |
Fixes #3793. Fixes #3794. Fixes #3795.
(But we may need to reopen these issues and #2914 in future once freestanding mode is added. See #1289.)
It seems to me that hosted implementations are required to provide all of these macros (see "Rejected alternatives" in WG21-P2198R7). I think it makes more sense to define them in older modes when the corresponding feature/header is available.
Possibly related question: should we leave feature-test macros for non-core components not defined when
_ENFORCE_ONLY_CORE_HEADERSis defined?