[clang-tools-extra] [clang-tidy]Fix PreferMemberInitializer false positive for reassignment (PR #70316)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 26 05:41:03 PDT 2023
================
@@ -54,31 +56,43 @@ static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
}
namespace {
+
AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
return Node.getFieldIndex() >= Index;
}
+
+enum class AssignedLevel { None, Assigned, UnsafetyAssigned };
+
} // namespace
// Checks if Field is initialised using a field that will be initialised after
// it.
// 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.
-static bool isSafeAssignment(const FieldDecl *Field, const Expr *Init,
- const CXXConstructorDecl *Context) {
+static AssignedLevel isSafeAssignment(const FieldDecl *Field, const Expr *Init,
+ const CXXConstructorDecl *Context,
+ AssignedLevel HistoryLevel) {
+ if (HistoryLevel == AssignedLevel::UnsafetyAssigned)
+ return AssignedLevel::UnsafetyAssigned;
+ if (Field->getType()->isReferenceType() &&
----------------
PiotrZSL wrote:
Read a CanonicalType here, teference could be from template, or from a typedef.
https://github.com/llvm/llvm-project/pull/70316
More information about the cfe-commits
mailing list