This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Update warning on some designator initializer cases involving unions
ClosedPublic

Authored by shafik on May 2 2023, 2:30 PM.

Details

Summary

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

Diff Detail

Event Timeline

shafik created this revision.May 2 2023, 2:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 2:30 PM
shafik requested review of this revision.May 2 2023, 2:30 PM
erichkeane accepted this revision.May 3 2023, 7:00 AM

I think this looks right, and is consistent with guidance from the bug report.

This revision is now accepted and ready to land.May 3 2023, 7:00 AM
shafik updated this revision to Diff 519960.May 5 2023, 1:38 PM
  • Apply clang-format
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 11:16 AM