forked from OSchip/llvm-project
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:
parent
72dc29a848
commit
4d2dff0148
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue