[clang] [clang-format] Fix misalignments of pointers in angle brackets (PR #106013)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 25 14:36:09 PDT 2024
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/106013
Fixes #105898.
>From a880299cd884d064e2bd03af308afa52736fa75d Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Sun, 25 Aug 2024 14:30:32 -0700
Subject: [PATCH] [clang-format] Fix misalignments of pointers in angle
brackets
Fixes #105898.
---
clang/lib/Format/WhitespaceManager.cpp | 3 ++-
clang/unittests/Format/FormatTest.cpp | 9 +++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index a31874a7c3195a..fa9585ab02eba2 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -469,7 +469,8 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
// except if the token is equal, then a space is needed.
if ((Style.PointerAlignment == FormatStyle::PAS_Right ||
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
- CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) {
+ CurrentChange.Spaces != 0 &&
+ !CurrentChange.Tok->isOneOf(tok::equal, TT_TemplateCloser)) {
const bool ReferenceNotRightAligned =
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index a383a624434b1f..e9a7e9654d3063 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -19314,6 +19314,15 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
"X = func<Type, Type>(looooooooooooooooooooooooong,\n"
" arrrrrrrrrrg);",
Alignment);
+
+ Alignment.ColumnLimit = 80;
+ Alignment.SpacesInAngles = FormatStyle::SIAS_Always;
+ verifyFormat("void **ptr = reinterpret_cast< void ** >(unkn);\n"
+ "ptr = reinterpret_cast< void ** >(ptr[0]);",
+ Alignment);
+ verifyFormat("quint32 *dstimg = reinterpret_cast< quint32 * >(out(i));\n"
+ "quint32 *dstmask = reinterpret_cast< quint32 * >(outmask(i));",
+ Alignment);
}
TEST_F(FormatTest, AlignConsecutiveBitFields) {
More information about the cfe-commits
mailing list