Index: clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp +++ clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp @@ -99,10 +99,9 @@ if (IdentifierInfo *II = ND->getIdentifier()) { StringRef NDName = II->getName(); llvm::SmallVector &Mapped = Mapper[skeleton(NDName)]; - const DeclContext *NDDecl = ND->getDeclContext(); for (const NamedDecl *OND : Mapped) { - if (!NDDecl->isDeclInLexicalTraversal(OND) && - !OND->getDeclContext()->isDeclInLexicalTraversal(ND)) + if (!ND->getDeclContext()->Encloses(OND->getDeclContext()) && + !OND->getDeclContext()->Encloses(ND->getDeclContext())) continue; if (OND->getIdentifier()->getName() != NDName) { diag(OND->getLocation(), "%0 is confusable with %1") Index: clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp @@ -18,8 +18,26 @@ int fi; // CHECK-MESSAGES: :[[#@LINE-1]]:5: note: other declaration found here +bool f0(const char *q1, const char *ql) { + // CHECK-MESSAGES: :[[#@LINE-1]]:21: warning: q1 is confusable with ql [misc-confusable-identifiers] + // CHECK-MESSAGES: :[[#@LINE-2]]:37: note: other declaration found here + return q1 < ql; +} + // should not print anything namespace ns { struct Foo {}; } // namespace ns auto f = ns::Foo(); + +struct Test { + void f1(const char *pl); +}; + +bool f2(const char *p1, const char *ql) { + return p1 < ql; +} + +bool f3(const char *q0, const char *q1) { + return q0 < q1; +}