Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init
authorliuke <liuke.gehry@bytedance.com>
Fri, 24 Sep 2021 17:14:09 +0000 (13:14 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Fri, 24 Sep 2021 17:15:21 +0000 (13:15 -0400)
commite4902480f1e2f12f73c2b504e3d717536653dd7b
tree2ef38a19490f48d476ac260206037a29a2c7b5f7
parent8dd42ffc09e30b1bf936f5da1aa104916e50d2fa
Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init

At most one variant member of a union may have a default member
initializer. The case of anonymous records with multiple levels of
nesting like the following also needs to meet this rule. The original
logic is to horizontally obtain all the member variables in a record
that need to be initialized and then filter to the variables that need
to be fixed. Obviously, it is impossible to correctly initialize the
desired variables according to the nesting relationship.

See Example 3 in class.union

union U {
  U() {}
  int x;  // int x{};
  union {
    int k;  // int k{};  <==  wrong fix
  };
  union {
    int z;  // int z{};  <== wrong fix
    int y;
  };
};
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp