Skip to content

Commit

Permalink
[clang-format] Fix a crash in QualifierAlignment: Right (#120821)
Browse files Browse the repository at this point in the history
Fixes #120793.
  • Loading branch information
owenca authored Dec 22, 2024
1 parent 3fa5b52 commit 40acaa3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Format/QualifierAlignmentFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
}
}

if (Next->is(tok::kw_auto))
if (Next && Next->is(tok::kw_auto))
TypeToken = Next;

// Place the Qualifier at the end of the list of qualifiers.
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/QualifierFixerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
verifyFormat("float (C::*const p)(int);", Style);
verifyFormat("float (C::*p)(int) const;", Style);
verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", Style);

Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.AfterFunction = true;
verifyFormat("auto foo() -> T const { return bar; }",
"auto foo() -> const T { return bar; }", Style);
}

TEST_F(QualifierFixerTest, LeftQualifier) {
Expand Down

0 comments on commit 40acaa3

Please sign in to comment.