99#include " UseUsingCheck.h"
1010#include " ../utils/LexerUtils.h"
1111#include " clang/AST/DeclGroup.h"
12+ #include " clang/Basic/LangOptions.h"
1213#include " clang/Basic/SourceLocation.h"
1314#include " clang/Basic/SourceManager.h"
1415#include " clang/Basic/TokenKinds.h"
@@ -88,6 +89,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
8889 return ;
8990
9091 const SourceManager &SM = *Result.SourceManager ;
92+ const LangOptions &LO = getLangOpts ();
9193
9294 // Match CXXRecordDecl only to store the range of the last non-implicit full
9395 // declaration, to later check whether it's within the typdef itself.
@@ -127,8 +129,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
127129
128130 const TypeLoc TL = MatchedDecl->getTypeSourceInfo ()->getTypeLoc ();
129131
130- auto [Type, QualifierStr] = [MatchedDecl, this , &TL,
131- &SM ]() -> std::pair<std::string, std::string> {
132+ auto [Type, QualifierStr] = [MatchedDecl, this , &TL, &SM,
133+ &LO ]() -> std::pair<std::string, std::string> {
132134 SourceRange TypeRange = TL.getSourceRange ();
133135
134136 // Function pointer case, get the left and right side of the identifier
@@ -137,12 +139,11 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
137139 const auto RangeLeftOfIdentifier = CharSourceRange::getCharRange (
138140 TypeRange.getBegin (), MatchedDecl->getLocation ());
139141 const auto RangeRightOfIdentifier = CharSourceRange::getCharRange (
140- Lexer::getLocForEndOfToken (MatchedDecl->getLocation (), 0 , SM,
141- getLangOpts ()),
142- Lexer::getLocForEndOfToken (TypeRange.getEnd (), 0 , SM, getLangOpts ()));
142+ Lexer::getLocForEndOfToken (MatchedDecl->getLocation (), 0 , SM, LO),
143+ Lexer::getLocForEndOfToken (TypeRange.getEnd (), 0 , SM, LO));
143144 const std::string VerbatimType =
144- (Lexer::getSourceText (RangeLeftOfIdentifier, SM, getLangOpts () ) +
145- Lexer::getSourceText (RangeRightOfIdentifier, SM, getLangOpts () ))
145+ (Lexer::getSourceText (RangeLeftOfIdentifier, SM, LO ) +
146+ Lexer::getSourceText (RangeRightOfIdentifier, SM, LO ))
146147 .str ();
147148 return {VerbatimType, " " };
148149 }
@@ -153,23 +154,22 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
153154 // pointer type seperately, so we need to sigure out if the new using-decl
154155 // needs to be to a reference or pointer as well.
155156 const SourceLocation Tok = utils::lexer::findPreviousAnyTokenKind (
156- MatchedDecl->getLocation (), SM, getLangOpts () , tok::TokenKind::star,
157+ MatchedDecl->getLocation (), SM, LO , tok::TokenKind::star,
157158 tok::TokenKind::amp, tok::TokenKind::comma,
158159 tok::TokenKind::kw_typedef);
159160
160161 ExtraReference = Lexer::getSourceText (
161- CharSourceRange::getCharRange (Tok, Tok.getLocWithOffset (1 )), SM,
162- getLangOpts ());
162+ CharSourceRange::getCharRange (Tok, Tok.getLocWithOffset (1 )), SM, LO);
163163
164164 if (ExtraReference != " *" && ExtraReference != " &" )
165165 ExtraReference = " " ;
166166
167167 TypeRange.setEnd (MainTypeEndLoc);
168168 }
169- return {Lexer::getSourceText ( CharSourceRange::getTokenRange (TypeRange), SM,
170- getLangOpts () )
171- .str (),
172- ExtraReference.str ()};
169+ return {
170+ Lexer::getSourceText ( CharSourceRange::getTokenRange (TypeRange), SM, LO )
171+ .str (),
172+ ExtraReference.str ()};
173173 }();
174174 StringRef Name = MatchedDecl->getName ();
175175 SourceRange ReplaceRange = MatchedDecl->getSourceRange ();
@@ -217,8 +217,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
217217 LastTagDeclRange->second .isValid () &&
218218 ReplaceRange.fullyContains (LastTagDeclRange->second )) {
219219 Type = std::string (Lexer::getSourceText (
220- CharSourceRange::getTokenRange (LastTagDeclRange->second ), SM,
221- getLangOpts ()));
220+ CharSourceRange::getTokenRange (LastTagDeclRange->second ), SM, LO));
222221 if (Type.empty ())
223222 return ;
224223 }
0 commit comments