Skip to content

Commit 9ec54c3

Browse files
owencatru
authored andcommitted
[clang-format] Fix misalignments of pointers in angle brackets (#106013)
Fixes #105898. (cherry picked from commit 656d5aa)
1 parent 32927ca commit 9ec54c3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
469469
// except if the token is equal, then a space is needed.
470470
if ((Style.PointerAlignment == FormatStyle::PAS_Right ||
471471
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
472-
CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) {
472+
CurrentChange.Spaces != 0 &&
473+
!CurrentChange.Tok->isOneOf(tok::equal, tok::r_paren,
474+
TT_TemplateCloser)) {
473475
const bool ReferenceNotRightAligned =
474476
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
475477
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;

clang/unittests/Format/FormatTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19186,6 +19186,24 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
1918619186
"X = func<Type, Type>(looooooooooooooooooooooooong,\n"
1918719187
" arrrrrrrrrrg);",
1918819188
Alignment);
19189+
19190+
Alignment.ColumnLimit = 80;
19191+
Alignment.SpacesInAngles = FormatStyle::SIAS_Always;
19192+
verifyFormat("void **ptr = reinterpret_cast< void ** >(unkn);\n"
19193+
"ptr = reinterpret_cast< void ** >(ptr[0]);",
19194+
Alignment);
19195+
verifyFormat("quint32 *dstimg = reinterpret_cast< quint32 * >(out(i));\n"
19196+
"quint32 *dstmask = reinterpret_cast< quint32 * >(outmask(i));",
19197+
Alignment);
19198+
19199+
Alignment.SpacesInParens = FormatStyle::SIPO_Custom;
19200+
Alignment.SpacesInParensOptions.InCStyleCasts = true;
19201+
verifyFormat("void **ptr = ( void ** )unkn;\n"
19202+
"ptr = ( void ** )ptr[0];",
19203+
Alignment);
19204+
verifyFormat("quint32 *dstimg = ( quint32 * )out.scanLine(i);\n"
19205+
"quint32 *dstmask = ( quint32 * )outmask.scanLine(i);",
19206+
Alignment);
1918919207
}
1919019208

1919119209
TEST_F(FormatTest, AlignConsecutiveBitFields) {

0 commit comments

Comments
 (0)