Skip to content

Commit 34621aa

Browse files
committed
Revert "[clang-tidy] Don't replace typedefs in extern c scope (#69102)"
This reverts commit 9dcc665.
1 parent 9dcc665 commit 34621aa

File tree

6 files changed

+7
-72
lines changed

6 files changed

+7
-72
lines changed

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,26 @@
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
2014

2115
namespace clang::tidy::modernize {
2216

23-
static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl";
2417
static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
2518
static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
2619
static constexpr llvm::StringLiteral TypedefName = "typedef";
2720

2821
UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
2922
: ClangTidyCheck(Name, Context),
30-
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
31-
IgnoreExternC(Options.get("IgnoreExternC", false)) {}
23+
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
3224

3325
void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3426
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
35-
Options.store(Opts, "IgnoreExternC", IgnoreExternC);
3627
}
3728

3829
void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
39-
Finder->addMatcher(
40-
typedefDecl(
41-
unless(isInstantiated()),
42-
optionally(hasAncestor(
43-
linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
44-
hasParent(decl().bind(ParentDeclName)))
45-
.bind(TypedefName),
46-
this);
30+
Finder->addMatcher(typedefDecl(unless(isInstantiated()),
31+
hasParent(decl().bind(ParentDeclName)))
32+
.bind(TypedefName),
33+
this);
4734

4835
// This matcher is used to find tag declarations in source code within
4936
// typedefs. They appear in the AST just *prior* to the typedefs.
@@ -83,11 +70,6 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
8370
if (MatchedDecl->getLocation().isInvalid())
8471
return;
8572

86-
const auto *ExternCDecl =
87-
Result.Nodes.getNodeAs<LinkageSpecDecl>(ExternCDeclName);
88-
if (ExternCDecl && IgnoreExternC)
89-
return;
90-
9173
SourceLocation StartLoc = MatchedDecl->getBeginLoc();
9274

9375
if (StartLoc.isMacroID() && IgnoreMacros)
@@ -140,8 +122,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
140122
Type = FirstTypedefName + Type.substr(FirstTypedefType.size() + 1);
141123
}
142124
if (!ReplaceRange.getEnd().isMacroID()) {
143-
const SourceLocation::IntTy Offset =
144-
MatchedDecl->getFunctionType() ? 0 : Name.size();
125+
const SourceLocation::IntTy Offset = MatchedDecl->getFunctionType() ? 0 : Name.size();
145126
LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Offset);
146127
}
147128

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace clang::tidy::modernize {
2020
class UseUsingCheck : public ClangTidyCheck {
2121

2222
const bool IgnoreMacros;
23-
const bool IgnoreExternC;
2423
SourceLocation LastReplacementEnd;
2524
llvm::DenseMap<const Decl *, SourceRange> LastTagDeclRanges;
2625

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,7 @@ Changes in existing checks
408408

409409
- Improved :doc:`modernize-use-using
410410
<clang-tidy/checks/modernize/use-using>` check to fix function pointer and
411-
forward declared ``typedef`` correctly. Added option `IgnoreExternC` to ignore ``typedef``
412-
declaration in ``extern "C"`` scope.
411+
forward declared ``typedef`` correctly.
413412

414413
- Improved :doc:`performance-faster-string-find
415414
<clang-tidy/checks/performance/faster-string-find>` check to properly escape

clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ After:
2828
using R_t = struct { int a; };
2929
using R_p = R_t*;
3030

31-
The checker ignores `typedef` within `extern "C" { ... }` blocks.
32-
33-
.. code-block:: c++
34-
35-
extern "C" {
36-
typedef int InExternC; // Left intact.
37-
}
38-
3931
This check requires using C++11 or higher to run.
4032

4133
Options
@@ -45,8 +37,3 @@ Options
4537

4638
If set to `true`, the check will not give warnings inside macros. Default
4739
is `true`.
48-
49-
.. option:: IgnoreExternC
50-
51-
If set to `true`, the check will not give warning inside `extern "C"`scope.
52-
Default is `false`

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,3 @@ 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-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
334-
// CHECK-FIXES: using InExternC = int;
335-
336-
}
337-
338-
extern "C++" {
339-
340-
typedef int InExternCPP;
341-
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
342-
// CHECK-FIXES: using InExternCPP = int;
343-
344-
}

0 commit comments

Comments
 (0)