[clang] [clang-format] Fix misalignments of pointers in angle brackets (PR #106013)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 25 14:36:40 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->105898.
---
Full diff: https://github.com/llvm/llvm-project/pull/106013.diff
2 Files Affected:
- (modified) clang/lib/Format/WhitespaceManager.cpp (+2-1)
- (modified) clang/unittests/Format/FormatTest.cpp (+9)
``````````diff
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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/106013
More information about the cfe-commits
mailing list