[PATCH] D50608: Silence GCC warning about broken strict aliasing rules
Kim Gräsman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 12 09:36:31 PDT 2018
kimgr updated this revision to Diff 160260.
kimgr retitled this revision from "[Alt] Silence GCC warning about broken strict aliasing rules" to "Silence GCC warning about broken strict aliasing rules".
kimgr edited the summary of this revision.
kimgr added a comment.
- Clarify comment
- Fix naming
- Update differential title/summary
https://reviews.llvm.org/D50608
Files:
include/llvm/Support/JSON.h
Index: include/llvm/Support/JSON.h
===================================================================
--- include/llvm/Support/JSON.h
+++ include/llvm/Support/JSON.h
@@ -452,7 +452,10 @@
new (reinterpret_cast<T *>(Union.buffer)) T(std::forward<U>(V)...);
}
template <typename T> T &as() const {
- return *reinterpret_cast<T *>(Union.buffer);
+ // Using this two-step static_cast via void * instead of reinterpret_cast
+ // silences a -Wstrict-aliasing false positive from GCC6 and earlier.
+ void *Storage = static_cast<void *>(Union.buffer);
+ return *static_cast<T *>(Storage);
}
template <typename Indenter>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50608.160260.patch
Type: text/x-patch
Size: 646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180812/2e3a3334/attachment.bin>
More information about the llvm-commits
mailing list