NFC: bit.h don't warn on strict aliasing for GCC <= 7.1

Summary: Addressed https://bugs.llvm.org/show_bug.cgi?id=38885

Subscribers: dexonsmith, llvm-commits, rsmith, steven_wu, RKSimon, Abhilash, srhines

Differential Revision: https://reviews.llvm.org/D51869

llvm-svn: 341853
This commit is contained in:
JF Bastien 2018-09-10 19:56:42 +00:00
parent 72dc29a848
commit 4d2dff0148
1 changed files with 8 additions and 0 deletions

View File

@ -26,7 +26,15 @@ template <typename To, typename From,
inline To bit_cast(const From &from) noexcept {
alignas(To) unsigned char storage[sizeof(To)];
std::memcpy(&storage, &from, sizeof(To));
#if defined(__GNUC__)
// Before GCC 7.2, GCC thought that this violated strict aliasing.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
return reinterpret_cast<To &>(storage);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
}
} // namespace llvm