From a7be6f1585697e7d276c5d3baa0a768b4e66bb85 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Wed, 15 May 2024 23:49:43 +0200 Subject: [PATCH] fix: gcc uninitialized warnings triggered by unsafe_default_initialized Despite all the `FOLLY_*_DISABLE_WARNING`, the implementation of `unsafe_default_initialized_cv` triggers hundreds of `-Wuninitialized` and `-Wmaybe-uninitialized` warnings when building with GCC 12, 13, 14. As much as I've tried, it seems impossible to silence the warnings purely by diagnostic pragmas. This change, however, eliminates all warnings, and the new should otherwise have the exact same effect as before. At least, I can see that clang / gcc both produce identical code before and after this change when using `unsafe_default_initialized` to initialize variables. --- folly/Utility.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/folly/Utility.h b/folly/Utility.h index 11576ab147d..926d99ff27d 100644 --- a/folly/Utility.h +++ b/folly/Utility.h @@ -493,8 +493,8 @@ struct unsafe_default_initialized_cv { #if __cpp_lib_is_constant_evaluated >= 201811L #if !defined(__MSVC_RUNTIME_CHECKS) if (!std::is_constant_evaluated()) { - T uninit; - return uninit; + aligned_storage_for_t uninit; + return reinterpret_cast(uninit); } #endif // !defined(__MSVC_RUNTIME_CHECKS) #endif