Skip to content

Commit

Permalink
fix: gcc uninitialized warnings triggered by unsafe_default_initialized
Browse files Browse the repository at this point in the history
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 code 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.
  • Loading branch information
mhx committed May 15, 2024
1 parent 3113fbf commit 4d27739
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions folly/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,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;
alignas(T) char uninit[sizeof(T)];
return *reinterpret_cast<T*>(uninit);
}
#endif // !defined(__MSVC_RUNTIME_CHECKS)
#endif
Expand Down

0 comments on commit 4d27739

Please sign in to comment.