================
@@ -0,0 +1,141 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MethodHidingCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include <stack>
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+bool sameBasicType(ParmVarDecl const *Lhs, ParmVarDecl const *Rhs) {
+ if (Lhs && Rhs) {
+ return Lhs->getType()
+ .getCanonicalType()
+ .getNonReferenceType()
+ .getUnqualifiedType() == Rhs->getType()
+ .getCanonicalType()
+ .getNonReferenceType()
+ .getUnqualifiedType();
+ }
+ return false;
+}
+
+bool namesCollide(CXXMethodDecl const &Lhs, CXXMethodDecl const &Rhs) {
+ if (Lhs.getNameAsString() != Rhs.getNameAsString()) {
+ return false;
+ }
+ if (Lhs.isConst() != Rhs.isConst()) {
+ return false;
+ }
+ if (Lhs.getNumParams() != Rhs.getNumParams()) {
+ return false;
+ }
+ for (unsigned int It = 0; It < Lhs.getNumParams(); ++It) {
+ if (!sameBasicType(Lhs.getParamDecl(It), Rhs.getParamDecl(It))) {
+ return false;
+ }
+ }
+ // Templates are not handled yet
+ if (Lhs.isTemplated() || Rhs.isTemplated()) {
+ return false;
+ }
+ if (Lhs.isTemplateInstantiation() || Rhs.isTemplateInstantiation()) {
+ return false;
+ }
+ if (Lhs.isFunctionTemplateSpecialization() ||
+ Rhs.isFunctionTemplateSpecialization()) {
+ return false;
+ }
----------------
t-a-james wrote:
A couple of things confuse me about this suggestion.
`isInTemplateInstantiation()` looks like this:
```
AST_MATCHER_FUNCTION(internal::Matcher<Stmt>, isInTemplateInstantiation) {
return stmt(hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
functionDecl(isTemplateInstantiation()),
varDecl(isTemplateInstantiation())))));
}
```
This expects a stmt, so i can't just write
`cxxMethodDecl(isTemplateInstantiation())`. I'd have to do something like this:
```
cxxMethodDecl(
has(
compoundStmt(
isInTemplateInstantiation()
)
)
)
```
Is that what you're intending?
(minimal example: https://godbolt.org/z/nco5Yorn8)
https://github.com/llvm/llvm-project/pull/154746
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits