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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits