Skip to content

Commit 40acaa3

Browse files
authored
[clang-format] Fix a crash in QualifierAlignment: Right (#120821)
Fixes #120793.
1 parent 3fa5b52 commit 40acaa3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
348348
}
349349
}
350350

351-
if (Next->is(tok::kw_auto))
351+
if (Next && Next->is(tok::kw_auto))
352352
TypeToken = Next;
353353

354354
// Place the Qualifier at the end of the list of qualifiers.

clang/unittests/Format/QualifierFixerTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
531531
verifyFormat("float (C::*const p)(int);", Style);
532532
verifyFormat("float (C::*p)(int) const;", Style);
533533
verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", Style);
534+
535+
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
536+
Style.BraceWrapping.AfterFunction = true;
537+
verifyFormat("auto foo() -> T const { return bar; }",
538+
"auto foo() -> const T { return bar; }", Style);
534539
}
535540

536541
TEST_F(QualifierFixerTest, LeftQualifier) {

0 commit comments

Comments
 (0)