diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h index 1e085f59b69ed..b2faf788d687a 100644 --- a/clang-tools-extra/clang-tidy/utils/Matchers.h +++ b/clang-tools-extra/clang-tidy/utils/Matchers.h @@ -112,7 +112,9 @@ class MatchesAnyListedNameMatcher case MatchMode::MatchFullyQualified: return Regex.match("::" + ND.getQualifiedNameAsString()); default: - return Regex.match(ND.getName()); + if (const IdentifierInfo *II = ND.getIdentifier()) + return Regex.match(II->getName()); + return false; } } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp index a8dda40651b7b..c6077a46b6e00 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp @@ -3,7 +3,7 @@ // RUN: [ \ // RUN: { \ // RUN: key: modernize-use-std-print.PrintfLikeFunctions, \ -// RUN: value: '::myprintf; mynamespace::myprintf2' \ +// RUN: value: 'unqualified_printf;::myprintf; mynamespace::myprintf2' \ // RUN: }, \ // RUN: { \ // RUN: key: modernize-use-std-print.FprintfLikeFunctions, \ @@ -14,7 +14,7 @@ // RUN: -- -isystem %clang_tidy_headers #include -#include +#include int myprintf(const char *, ...); int myfprintf(FILE *fp, const char *, ...); @@ -85,3 +85,10 @@ int fprintf_uses_return_value(int i) { // CHECK-MESSAGES-NOT: [[@LINE-1]]:10: warning: use 'std::println' instead of 'myprintf' [modernize-use-std-print] // CHECK-FIXES-NOT: std::println(stderr, "return value {}", i); } + +// Ensure that MatchesAnyListedNameMatcher::NameMatcher::match() can cope with a +// NamedDecl that has no name when we're trying to match unqualified_printf. +void no_name(const std::string &in) +{ + "A" + in; +}