[PATCH] D96725: [clang-tidy] Fix modernize-use-using in extern C code
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 15 10:48:09 PST 2021
njames93 updated this revision to Diff 323796.
njames93 added a comment.
Newline.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96725/new/
https://reviews.llvm.org/D96725
Files:
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
@@ -302,3 +302,10 @@
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
// CHECK-FIXES: using b = InjectedClassNameWithUnnamedArgument;
};
+
+extern "C" {
+typedef int CType;
+typedef struct {
+ int b;
+} CStruct;
+}
Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -16,6 +16,10 @@
namespace tidy {
namespace modernize {
+AST_MATCHER(Decl, isInExternC) {
+ return Node.getDeclContext()->isExternCContext();
+}
+
UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
@@ -25,8 +29,10 @@
}
void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
- this);
+ Finder->addMatcher(
+ typedefDecl(unless(isInstantiated()), unless(isInExternC()))
+ .bind("typedef"),
+ this);
// This matcher used to find tag declarations in source code within typedefs.
// They appear in the AST just *prior* to the typedefs.
Finder->addMatcher(tagDecl(unless(isImplicit())).bind("tagdecl"), this);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96725.323796.patch
Type: text/x-patch
Size: 1666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210215/684e5557/attachment.bin>
More information about the cfe-commits
mailing list