Skip to content

Commit 2115665

Browse files
committed
Fix #35272: Don't replace typedefs in extern c scope
1 parent 8ee38f3 commit 2115665

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include "clang/Lex/Lexer.h"
1212

1313
using namespace clang::ast_matchers;
14+
namespace {
15+
16+
AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
17+
return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
18+
}
19+
} // namespace
1420

1521
namespace clang::tidy::modernize {
1622

@@ -27,10 +33,12 @@ void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2733
}
2834

2935
void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
30-
Finder->addMatcher(typedefDecl(unless(isInstantiated()),
31-
hasParent(decl().bind(ParentDeclName)))
32-
.bind(TypedefName),
33-
this);
36+
Finder->addMatcher(
37+
typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
38+
isExternCLinkage())))),
39+
hasParent(decl().bind(ParentDeclName)))
40+
.bind(TypedefName),
41+
this);
3442

3543
// This matcher is used to find tag declarations in source code within
3644
// typedefs. They appear in the AST just *prior* to the typedefs.

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
325325
typedef class ISSUE_67529_1 *ISSUE_67529;
326326
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
327327
// CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
328+
329+
// Some Header
330+
extern "C" {
331+
332+
typedef int InExternC;
333+
}
334+
335+
extern "C++" {
336+
337+
typedef int InExternCPP;
338+
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
339+
// CHECK-FIXES: using InExternCPP = int;
340+
341+
}

0 commit comments

Comments
 (0)