Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ void UnconventionalAssignOperatorCheck::registerMatchers(
const auto HasGoodReturnType =
cxxMethodDecl(returns(hasCanonicalType(lValueReferenceType(pointee(
unless(isConstQualified()),
anyOf(autoType(), hasDeclaration(equalsBoundNode("class"))))))));
anyOf(autoType(),
hasDeclaration(declaresSameEntityAsBoundNode("class"))))))));

const auto IsSelf = qualType(hasCanonicalType(
anyOf(hasDeclaration(equalsBoundNode("class")),
referenceType(pointee(hasDeclaration(equalsBoundNode("class")))))));
anyOf(hasDeclaration(declaresSameEntityAsBoundNode("class")),
referenceType(pointee(
hasDeclaration(declaresSameEntityAsBoundNode("class")))))));
const auto IsAssign =
cxxMethodDecl(unless(anyOf(isDeleted(), isPrivate(), isImplicit())),
hasName("operator="), ofClass(recordDecl().bind("class")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,11 @@ struct TemplateAssignment {
}
};
}

namespace GH153770 {
struct A;
struct A {
A() = default;
A& operator=(const A&) = default;
};
} // namespace GH153770
8 changes: 8 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5739,6 +5739,14 @@ AST_POLYMORPHIC_MATCHER_P(equalsBoundNode,
return Builder->removeBindings(Predicate);
}

/// Matches a declaration if it declares the same entity as the node previously
/// bound to \p ID.
AST_MATCHER_P(Decl, declaresSameEntityAsBoundNode, std::string, ID) {
return Builder->removeBindings([&](const internal::BoundNodesMap &Nodes) {
return !clang::declaresSameEntity(&Node, Nodes.getNodeAs<Decl>(ID));
});
}

/// Matches the condition variable statement in an if statement.
///
/// Given
Expand Down
1 change: 1 addition & 0 deletions clang/lib/ASTMatchers/Dynamic/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(enumDecl);
REGISTER_MATCHER(enumType);
REGISTER_MATCHER(equalsBoundNode);
REGISTER_MATCHER(declaresSameEntityAsBoundNode);
REGISTER_MATCHER(equalsIntegralValue);
REGISTER_MATCHER(explicitCastExpr);
REGISTER_MATCHER(exportDecl);
Expand Down