[all-commits] [llvm/llvm-project] e49024: Fix wrong FixIt about union in cppcoreguidelines-p...

Liu Ke via All-commits all-commits at lists.llvm.org
Fri Sep 24 10:15:38 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e4902480f1e2f12f73c2b504e3d717536653dd7b
      https://github.com/llvm/llvm-project/commit/e4902480f1e2f12f73c2b504e3d717536653dd7b
  Author: liuke <liuke.gehry at bytedance.com>
  Date:   2021-09-24 (Fri, 24 Sep 2021)

  Changed paths:
    M clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
    M clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp

  Log Message:
  -----------
  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;
  };
};




More information about the All-commits mailing list