[clang-tidy] fix false positive when member initialization depends on structured binging variable in cppcoreguidelines-prefer-member-initializer (#108743)
Fixes: #82970 Detecting dependiences with `varDecl` is too strict. It will ignore the `bingingDecl`. This patch wants to use `valueDecl` to match more cases including `bingingDecl`.
This commit is contained in:
parent
0b041f1da5
commit
7deca859e5
@ -83,7 +83,7 @@ static void updateAssignmentLevel(
|
||||
memberExpr(hasObjectExpression(cxxThisExpr()),
|
||||
member(fieldDecl(indexNotLessThan(Field->getFieldIndex()))));
|
||||
auto DeclMatcher = declRefExpr(
|
||||
to(varDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Ctor)))));
|
||||
to(valueDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Ctor)))));
|
||||
const bool HasDependence = !match(expr(anyOf(MemberMatcher, DeclMatcher,
|
||||
hasDescendant(MemberMatcher),
|
||||
hasDescendant(DeclMatcher))),
|
||||
|
@ -111,6 +111,11 @@ Changes in existing checks
|
||||
<clang-tidy/checks/bugprone/casting-through-void>` check to suggest replacing
|
||||
the offending code with ``reinterpret_cast``, to more clearly express intent.
|
||||
|
||||
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
|
||||
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to avoid
|
||||
false positive when member initialization depends on a structured binging
|
||||
variable.
|
||||
|
||||
- Improved :doc:`modernize-use-std-format
|
||||
<clang-tidy/checks/modernize/use-std-format>` check to support replacing
|
||||
member function calls too.
|
||||
|
@ -639,3 +639,14 @@ struct S3 {
|
||||
T M;
|
||||
};
|
||||
}
|
||||
|
||||
namespace GH82970 {
|
||||
struct InitFromBingingDecl {
|
||||
int m;
|
||||
InitFromBingingDecl() {
|
||||
struct { int i; } a;
|
||||
auto [n] = a;
|
||||
m = n;
|
||||
}
|
||||
};
|
||||
} // namespace GH82970
|
||||
|
Loading…
x
Reference in New Issue
Block a user