[PATCH] D154884: [clang-tidy] Make MatchesAnyListedNameMatcher cope with unnamed Decl
Mike Crowe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 11 00:54:23 PDT 2023
mikecrowe updated this revision to Diff 538940.
mikecrowe marked an inline comment as done.
mikecrowe added a comment.
Remove unnecessary init-statement and test case in commit message
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154884/new/
https://reviews.llvm.org/D154884
Files:
clang-tools-extra/clang-tidy/utils/Matchers.h
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
+++ 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 <cstdio>
-#include <string.h>
+#include <string>
int myprintf(const char *, ...);
int myfprintf(FILE *fp, const char *, ...);
@@ -85,3 +85,10 @@
// 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;
+}
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -112,7 +112,9 @@
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154884.538940.patch
Type: text/x-patch
Size: 1931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230711/ab5f3471/attachment.bin>
More information about the cfe-commits
mailing list