Skip to content

Commit 91d4465

Browse files
committed
address review comment regarding readability of getting the source text
1 parent 14ff78e commit 91d4465

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,27 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
131131
// Function pointer case, get the left and right side of the identifier
132132
// without the identifier.
133133
if (TypeRange.fullyContains(MatchedDecl->getLocation())) {
134-
return {(Lexer::getSourceText(
135-
CharSourceRange::getCharRange(TL.getBeginLoc(),
136-
MatchedDecl->getLocation()),
137-
*Result.SourceManager, getLangOpts()) +
138-
Lexer::getSourceText(
139-
CharSourceRange::getCharRange(
140-
Lexer::getLocForEndOfToken(MatchedDecl->getLocation(), 0,
141-
*Result.SourceManager,
142-
getLangOpts()),
143-
Lexer::getLocForEndOfToken(TL.getEndLoc(), 0,
144-
*Result.SourceManager,
145-
getLangOpts())),
146-
*Result.SourceManager, getLangOpts()))
147-
.str(),
148-
""};
134+
const auto RangeLeftOfIdentifier = CharSourceRange::getCharRange(
135+
TypeRange.getBegin(), MatchedDecl->getLocation());
136+
const auto RangeRightOfIdentifier = CharSourceRange::getCharRange(
137+
Lexer::getLocForEndOfToken(MatchedDecl->getLocation(), 0,
138+
*Result.SourceManager, getLangOpts()),
139+
Lexer::getLocForEndOfToken(TypeRange.getEnd(), 0,
140+
*Result.SourceManager, getLangOpts()));
141+
const std::string VerbatimType =
142+
(Lexer::getSourceText(RangeLeftOfIdentifier, *Result.SourceManager,
143+
getLangOpts()) +
144+
Lexer::getSourceText(RangeRightOfIdentifier, *Result.SourceManager,
145+
getLangOpts()))
146+
.str();
147+
return {VerbatimType, ""};
149148
}
150149

151150
StringRef ExtraReference = "";
152151
if (MainTypeEndLoc.isValid() && TypeRange.fullyContains(MainTypeEndLoc)) {
152+
// Each type introduced in a typedef can specify being a reference or
153+
// pointer type seperately, so we need to sigure out if the new using-decl
154+
// needs to be to a reference or pointer as well.
153155
const SourceLocation Tok = utils::lexer::findPreviousAnyTokenKind(
154156
MatchedDecl->getLocation(), *Result.SourceManager, getLangOpts(),
155157
tok::TokenKind::star, tok::TokenKind::amp, tok::TokenKind::comma,

0 commit comments

Comments
 (0)