[PATCH] D35472: Implement P0463R1: "Endian just Endian"

David Majnemer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 10:14:09 PDT 2017

majnemer added inline comments.

Comment at: test/std/utilities/meta/meta.type.synop/endian.pass.cpp:39-42
+    union {
+        uint32_t i;
+        char c[4];
+    } u = {0x01020304};
This is undefined behavior as-is because you are reading from a union member other than the active union member.

I'd recommend a sequence like:
  uint32_t i = 0x01020304;
  char c[4];
  memcpy(c, &i, 4);


More information about the cfe-commits mailing list