[Clang] Update warning on some designator initializer cases involving unions
authorShafik Yaghmour <shafik.yaghmour@intel.com>
Mon, 8 May 2023 18:13:08 +0000 (11:13 -0700)
committerShafik Yaghmour <shafik.yaghmour@intel.com>
Mon, 8 May 2023 18:14:33 +0000 (11:14 -0700)
commit96bc78631f16fe5ce2e7e6000b74d790b32f7a16
tree5bac08570586a9f015b5cd383adc7bca44c5f8fa
parent0dec49cb3466c7fe116030a568be423c6aa5bdf3
[Clang] Update warning on some designator initializer cases involving unions

Currently when using designated initializers in C++ we have a few
extension. Two extension which are dangerous involved assigning to
multiple members of union which will likely be a mistake since unions
can only have one active member. I have updated to be a warning by
default.

The second case if when we assign to multiple union members and one of
the previous members had a non-trivial destructor, which could lead to
leaking resources. This one is now an error by default.

Fixes: https://github.com/llvm/llvm-project/issues/62156

Differential Revision:  https://reviews.llvm.org/D149694
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/cxx2b-designated-initializers.cpp