diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp +++ b/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); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp +++ b/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; +}