Skip to content

Commit 498652d

Browse files
committed
wip
1 parent 3c0d4aa commit 498652d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,16 @@ static bool isQualifier(const FormatToken *const Tok) {
177177

178178
const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
179179
const SourceManager &SourceMgr, const AdditionalKeywords &Keywords,
180-
tooling::Replacements &Fixes, const FormatToken *const Tok,
180+
tooling::Replacements &Fixes, const FormatToken *Tok,
181181
const std::string &Qualifier, tok::TokenKind QualifierType) {
182182
// We only need to think about streams that begin with a qualifier.
183183
if (Tok->isNot(QualifierType))
184184
return Tok;
185+
186+
const auto *Next = Tok->getNextNonComment();
187+
185188
// Don't concern yourself if nothing follows the qualifier.
186-
if (!Tok->Next)
189+
if (!Next)
187190
return Tok;
188191

189192
// Skip qualifiers to the left to find what preceeds the qualifiers.
@@ -247,9 +250,15 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
247250
}();
248251

249252
// Find the last qualifier to the right.
250-
const FormatToken *LastQual = Tok;
251-
while (isQualifier(LastQual->getNextNonComment()))
252-
LastQual = LastQual->getNextNonComment();
253+
const auto *LastQual = Tok;
254+
for (; isQualifier(Next); Next = Next->getNextNonComment())
255+
LastQual = Next;
256+
257+
if (!LastQual || !Next ||
258+
(LastQual->isOneOf(tok::kw_const, tok::kw_volatile) &&
259+
Next->isOneOf(Keywords.kw_override, Keywords.kw_final))) {
260+
return Tok;
261+
}
253262

254263
// If this qualifier is to the right of a type or pointer do a partial sort
255264
// and return.

0 commit comments

Comments
 (0)