[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:47:26 PST 2021
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh.
Herald added a subscriber: xazax.hun.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The check currently erroneously flags typedefs in extern "C" blocks.
Addresses https://bugs.llvm.org/show_bug.cgi?id=49181
Repository:
rG LLVM Github Monorepo
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;
+}
\ No newline at end of file
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.323795.patch
Type: text/x-patch
Size: 1694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210215/2372deb3/attachment.bin>
More information about the cfe-commits
mailing list