@@ -75,19 +75,27 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
75
75
// consecutive TypedefDecl nodes whose SourceRanges overlap. Each range starts
76
76
// at the "typedef" and then continues *across* previous definitions through
77
77
// the end of the current TypedefDecl definition.
78
+ const Token TokenBeforeName =
79
+ *Lexer::findPreviousToken (MatchedDecl.getLocation (), SM, LO,
80
+ /* IncludeComments=*/ false );
78
81
const SourceRange RemovalRange = {
79
- Lexer::findPreviousToken (MatchedDecl.getLocation (), SM, LO,
80
- /* IncludeComments=*/ true )
81
- ->getEndLoc (),
82
+ TokenBeforeName.getEndLoc (),
82
83
Lexer::getLocForEndOfToken (MatchedDecl.getLocation (), 1 , SM, LO)};
83
84
if (NextTypedefStartsANewSequence) {
84
- diag (MatchedDecl.getBeginLoc (), UseUsingWarning)
85
- << FixItHint::CreateReplacement (
86
- {MatchedDecl.getBeginLoc (),
87
- Lexer::getLocForEndOfToken (MatchedDecl.getBeginLoc (), 0 , SM,
88
- LO)},
89
- (" using " + MatchedDecl.getName () + " =" ).str ())
90
- << FixItHint::CreateRemoval (RemovalRange);
85
+ auto Diag = diag (MatchedDecl.getBeginLoc (), UseUsingWarning)
86
+ << FixItHint::CreateInsertion (
87
+ MatchedDecl.getBeginLoc (),
88
+ (" using " + MatchedDecl.getName () + " =" ).str ())
89
+ << FixItHint::CreateRemoval (RemovalRange);
90
+
91
+ Token FirstToken;
92
+ Lexer::getRawToken (MatchedDecl.getBeginLoc (), FirstToken, SM, LO);
93
+ if (FirstToken.getRawIdentifier () == " typedef" )
94
+ Diag << FixItHint::CreateRemoval (FirstToken.getLocation ());
95
+
96
+ if (TokenBeforeName.getRawIdentifier () == " typedef" )
97
+ Diag << FixItHint::CreateRemoval (TokenBeforeName.getLocation ());
98
+
91
99
FirstTypedefName = MatchedDecl.getName ();
92
100
} else {
93
101
diag (LastCommaOrSemi, UseUsingWarning)
0 commit comments