[PATCH] D63753: [Sema] Instead of rejecting C unions with non-trivial fields, detect attempts to destruct/initialize/copy them.

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 10 18:48:55 PDT 2019


ahatanak marked 2 inline comments as done.
ahatanak added inline comments.


================
Comment at: lib/Sema/SemaDecl.cpp:12053
+                            NTCUC_UninitAutoVar);
     }
+
----------------
rjmccall wrote:
> Please add a comment explaining why this is specific to local variables.
I was trying to explain why this should be specific to local variables and realized that it's not clear to me whether it should be.

Suppose there is a union with two fields that are both non-trivial:

```
union U {
  Type A a;
  Type B a;
};

U global;
```

In this case, is value-initialization (which is essentially default-initialization plus a bunch of zero-initialization as per our previous discussion) used to initialize `global`? If so, should we reject the code since it requires default-initialization? It should be fine if we can assume default-initialization means zero-initialization for non-trivial types in C, but what if `TypeA` or `TypeB` requires initializing to a non-zero value?


Repository:
  rC Clang

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

https://reviews.llvm.org/D63753





More information about the cfe-commits mailing list