Skip to content

Commit 656d5aa

Browse files
authored
[clang-format] Fix misalignments of pointers in angle brackets (#106013)
Fixes #105898.
1 parent 815bf0f commit 656d5aa

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
@@ -19314,6 +19314,24 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
1931419314
"X = func<Type, Type>(looooooooooooooooooooooooong,\n"
1931519315
" arrrrrrrrrrg);",
1931619316
Alignment);
19317+
19318+
Alignment.ColumnLimit = 80;
19319+
Alignment.SpacesInAngles = FormatStyle::SIAS_Always;
19320+
verifyFormat("void **ptr = reinterpret_cast< void ** >(unkn);\n"
19321+
"ptr = reinterpret_cast< void ** >(ptr[0]);",
19322+
Alignment);
19323+
verifyFormat("quint32 *dstimg = reinterpret_cast< quint32 * >(out(i));\n"
19324+
"quint32 *dstmask = reinterpret_cast< quint32 * >(outmask(i));",
19325+
Alignment);
19326+
19327+
Alignment.SpacesInParens = FormatStyle::SIPO_Custom;
19328+
Alignment.SpacesInParensOptions.InCStyleCasts = true;
19329+
verifyFormat("void **ptr = ( void ** )unkn;\n"
19330+
"ptr = ( void ** )ptr[0];",
19331+
Alignment);
19332+
verifyFormat("quint32 *dstimg = ( quint32 * )out.scanLine(i);\n"
19333+
"quint32 *dstmask = ( quint32 * )outmask.scanLine(i);",
19334+
Alignment);
1931719335
}
1931819336

1931919337
TEST_F(FormatTest, AlignConsecutiveBitFields) {

0 commit comments

Comments
 (0)