Skip to content

Commit 6330f1e

Browse files
authored
[clang-format] Fix a regression in PointerAlignment: Left (llvm#124085)
Don't insert a space between a type declaration r_paren and &/&&. Fixes llvm#124073.
1 parent 2f39d13 commit 6330f1e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5488,8 +5488,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
54885488
}
54895489
if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
54905490
return ShouldAddSpacesInAngles();
5491-
if (Left.is(tok::r_paren) && Right.is(TT_PointerOrReference) &&
5492-
Right.isOneOf(tok::amp, tok::ampamp)) {
5491+
if (Left.is(tok::r_paren) && Left.isNot(TT_TypeDeclarationParen) &&
5492+
Right.is(TT_PointerOrReference) && Right.isOneOf(tok::amp, tok::ampamp)) {
54935493
return true;
54945494
}
54955495
// Space before TT_StructuredBindingLSquare.

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,6 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
20842084
Style);
20852085

20862086
Style.PointerAlignment = FormatStyle::PAS_Left;
2087-
Style.ReferenceAlignment = FormatStyle::RAS_Pointer;
20882087
verifyFormat("int* f1(int* a, int& b, int&& c);", Style);
20892088
verifyFormat("int& f2(int&& c, int* a, int& b);", Style);
20902089
verifyFormat("int&& f3(int& b, int&& c, int* a);", Style);
@@ -2118,6 +2117,7 @@ TEST_F(FormatTest, SeparatePointerReferenceAlignment) {
21182117
"function<int(int&)> res1 = [](int& a) { return 0000000000000; },\n"
21192118
" res2 = [](int& a) { return 0000000000000; };",
21202119
Style);
2120+
verifyFormat("[](decltype(foo)& Bar) {}", Style);
21212121

21222122
Style.AlignConsecutiveDeclarations.Enabled = true;
21232123
Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;

0 commit comments

Comments
 (0)