From 707115ee7ee879ced7b77dd187a71044aeabd77e Mon Sep 17 00:00:00 2001 From: Ian Petersen Date: Thu, 1 Dec 2022 02:30:57 -0800 Subject: [PATCH] Fix Yoga's conditional use of std::bit_cast<>() Summary: Yoga tries to use `std::bit_cast<>()` where it's available and falls back to `std::memcpy()` everywhere else. Unfortunately, the feature-test macro (`__cpp_lib_bit_cast`) is only defined if the feature is available *and you have already included either `` or ``* (or something else that includes one of those). Since `CompactValue.h` checks `__cpp_lib_bit_cast` *first*, it's not defined even if it *would be* defined, leading the header not to `#include `, leaving `std::bit_cast<>()` undefined; later, other headers from the STL are included, leading to `__cpp_lib_bit_cast` *becoming* defined and causing later code to choose to use the undefind `std::bit_cast<>()`. This diff fixes the problem by `#include`ing either `` or `` (depending on availability) before checking any feature-test macros. Changelog: [Internal] Reviewed By: smeenai Differential Revision: D41641205 fbshipit-source-id: 7d7bc5791c902a45302d3707e6cbf21fc0493f0c --- yoga/CompactValue.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index 6568c48a..e489fbb6 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -9,6 +9,14 @@ #ifdef __cplusplus +#if defined(__has_include) && __has_include() +// needed to be able to evaluate defined(__cpp_lib_bit_cast) +#include +#else +// needed to be able to evaluate defined(__cpp_lib_bit_cast) +#include +#endif + #ifdef __cpp_lib_bit_cast #include #else