[clang-tools-extra] [clang-tidy]Fix PreferMemberInitializer false positive for reassignment (PR #70316)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 22:09:14 PDT 2023
================
@@ -570,3 +570,19 @@ struct PR52818 {
int bar;
};
+
+struct RefReassignment {
+ RefReassignment(int &i) : m_i{i} {
+ m_i = 1;
+ }
+ int & m_i;
+};
+
+struct ReassignmentAfterUnsafetyAssignment {
+ ReassignmentAfterUnsafetyAssignment() {
+ int a = 10;
+ m_i = a;
+ m_i = 1;
+ }
+ int m_i;
+};
----------------
HerrCai0907 wrote:
positive tests still have some issue. It will report for each assignments. But I don't find a good solution to handle this case. It's already marked in `isSafeAssignment`.
```c++
// TODO: Probably should guard against function calls that could have side
// effects or if they do reference another field that's initialized before this
// field, but is modified before the assignment.
```
https://github.com/llvm/llvm-project/pull/70316
More information about the cfe-commits
mailing list