[PATCH] D80055: Diagnose union tail padding

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 15 21:11:27 PDT 2020


jfb marked an inline comment as done.
jfb added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:264
+def warn_union_tail_padding_uninitialized : Warning<
+  "Initializing union %0 field %1 only initializes the first %2 of %3 bytes, leaving the remaining %4 bytes undefined">,
+  InGroup<UnionTailPadding>;
----------------
Something which I'm not sure matters:

```
union Unnamed {
  union {
    int i;
    float f;
  };
  char bytes[8];
};

union Unnamed unnamed = { 42 };
```

Will generate the following diagnostic:

```
warning: Initializing union 'Unnamed' field '' only initializes the first 4 of 8 bytes, leaving the remaining 4 bytes undefined [-Wunion-tail-padding]
union Unnamed unnamed = { 42 };
                        ^
```

I think that's generally how we handle unnamed members anyways?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80055/new/

https://reviews.llvm.org/D80055





More information about the cfe-commits mailing list