[PATCH] D50608: [Support][JSON][NFC] Silence GCC warning about broken strict aliasing rules

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 12 10:32:25 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL339521: [Support][JSON][NFC] Silence GCC warning about broken strict aliasing rules (authored by xbolva00, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50608?vs=160260&id=160262#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50608

Files:
  llvm/trunk/include/llvm/Support/JSON.h


Index: llvm/trunk/include/llvm/Support/JSON.h
===================================================================
--- llvm/trunk/include/llvm/Support/JSON.h
+++ llvm/trunk/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.160262.patch
Type: text/x-patch
Size: 679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180812/62797404/attachment.bin>


More information about the llvm-commits mailing list