[clang-format] Fix a regression in PointerAlignment: Left (#124085)

Don't insert a space between a type declaration r_paren and &/&&.

Fixes #124073.
This commit is contained in:
Owen Pan 2025-01-23 21:44:29 -08:00 committed by GitHub
parent 2f39d138dc
commit 6330f1e052
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -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.

View File

@ -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);
@ -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;