Skip to content

Commit

Permalink
[clang-format] Fix a regression in PointerAlignment: Left
Browse files Browse the repository at this point in the history
Don't insert a space between a type declaration r_paren and &/&&.

Fixes #124073.
  • Loading branch information
owenca committed Jan 23, 2025
1 parent 5d76642 commit 4a6d683
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5488,8 +5488,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
}
if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
return ShouldAddSpacesInAngles();
if (Left.is(tok::r_paren) && Right.is(TT_PointerOrReference) &&
Right.isOneOf(tok::amp, tok::ampamp)) {
if (Left.is(tok::r_paren) && Left.isNot(TT_TypeDeclarationParen) &&
Right.is(TT_PointerOrReference) && Right.isOneOf(tok::amp, tok::ampamp)) {
return true;
}
// Space before TT_StructuredBindingLSquare.
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
Style);

Style.PointerAlignment = FormatStyle::PAS_Left;
Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
verifyFormat("int* f1(int* a, int& b, int&& c);", Style);
verifyFormat("int& f2(int&& c, int* a, int& b);", Style);
verifyFormat("int&& f3(int& b, int&& c, int* a);", Style);
Expand Down Expand Up @@ -2118,6 +2117,7 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
"function<int(int&)> res1 = [](int& a) { return 0000000000000; },\n"
" res2 = [](int& a) { return 0000000000000; };",
Style);
verifyFormat("[](decltype(foo)& Bar) {}", Style);

Style.AlignConsecutiveDeclarations.Enabled = true;
Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
Expand Down

0 comments on commit 4a6d683

Please sign in to comment.