[PATCH] D73090: [clang-tidy] Fix PR#44528 'modernize-use-using and enums'
Karasev Nikita via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 22:19:51 PST 2020
f00kat updated this revision to Diff 239491.
f00kat added a comment.
Add new line in the end of file checkers/modernize-use-using.cpp
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73090/new/
https://reviews.llvm.org/D73090
Files:
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
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
@@ -267,3 +267,7 @@
// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: use 'using' instead of 'typedef'
// CHECK-FIXES: using R_t = struct { int a; };
// CHECK-FIXES-NEXT: using R_p = R_t*;
+
+typedef enum { ea, eb } EnumT;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using EnumT = enum { ea, eb };
Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
@@ -23,7 +23,7 @@
const bool IgnoreMacros;
SourceLocation LastReplacementEnd;
- SourceRange LastCxxDeclRange;
+ SourceRange LastTagDeclRange;
std::string FirstTypedefType;
std::string FirstTypedefName;
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
@@ -25,18 +25,18 @@
return;
Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
this);
- // This matcher used to find structs defined in source code within typedefs.
+ // This matcher`s used to find structs/enums defined in source code within typedefs.
// They appear in the AST just *prior* to the typedefs.
- Finder->addMatcher(cxxRecordDecl(unless(isImplicit())).bind("struct"), this);
+ Finder->addMatcher(cxxRecordDecl(unless(isImplicit())).bind("tagdecl"), this);
+ Finder->addMatcher(enumDecl(unless(isImplicit())).bind("tagdecl"), this);
}
void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
// Match CXXRecordDecl only to store the range of the last non-implicit full
// declaration, to later check whether it's within the typdef itself.
- const auto *MatchedCxxRecordDecl =
- Result.Nodes.getNodeAs<CXXRecordDecl>("struct");
- if (MatchedCxxRecordDecl) {
- LastCxxDeclRange = MatchedCxxRecordDecl->getSourceRange();
+ const auto *MatchedTagDecl = Result.Nodes.getNodeAs<TagDecl>("tagdecl");
+ if (MatchedTagDecl) {
+ LastTagDeclRange = MatchedTagDecl->getSourceRange();
return;
}
@@ -96,10 +96,10 @@
auto Diag = diag(ReplaceRange.getBegin(), UseUsingWarning);
// If typedef contains a full struct/class declaration, extract its full text.
- if (LastCxxDeclRange.isValid() && ReplaceRange.fullyContains(LastCxxDeclRange)) {
+ if (LastTagDeclRange.isValid() && ReplaceRange.fullyContains(LastTagDeclRange)) {
bool Invalid;
Type =
- Lexer::getSourceText(CharSourceRange::getTokenRange(LastCxxDeclRange),
+ Lexer::getSourceText(CharSourceRange::getTokenRange(LastTagDeclRange),
*Result.SourceManager, getLangOpts(), &Invalid);
if (Invalid)
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73090.239491.patch
Type: text/x-patch
Size: 3194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200122/905fea1f/attachment-0001.bin>
More information about the cfe-commits
mailing list