[PATCH] D50710: [ADT] Fix Optional ABI mismatch between clang & gcc

Tim Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 20 10:01:14 PDT 2018


timshen added inline comments.


================
Comment at: include/llvm/ADT/Optional.h:120
   OptionalStorage &operator=(const T &y) {
-    *reinterpret_cast<T *>(storage.buffer) = y;
-    hasVal = true;
+    if (hasVal) {
+      // Use std::addressof to silence strict-aliasing warnings from gcc.
----------------
Will this suffice?
`if (hasVal) { memcpy(&storage.buffer, &y.storage.buffer, sizeof(T)); }`


Repository:
  rL LLVM

https://reviews.llvm.org/D50710





More information about the llvm-commits mailing list