[clang] [clang-format] Don't break before *const (PR #128817)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 25 20:45:51 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->28919
---
Full diff: https://github.com/llvm/llvm-project/pull/128817.diff
2 Files Affected:
- (modified) clang/lib/Format/TokenAnnotator.cpp (+2-1)
- (modified) clang/unittests/Format/FormatTest.cpp (+3)
``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 2ffaee93b70ea..3a49650d95ba4 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -6196,7 +6196,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return Line.IsMultiVariableDeclStmt ||
(getTokenPointerOrReferenceAlignment(Right) ==
FormatStyle::PAS_Right &&
- (!Right.Next || Right.Next->isNot(TT_FunctionDeclarationName)));
+ !(Right.Next &&
+ Right.Next->isOneOf(TT_FunctionDeclarationName, tok::kw_const)));
}
if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
TT_ClassHeadName, tok::kw_operator)) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 39266d17f824f..a51c7eb7ddb96 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4642,6 +4642,9 @@ TEST_F(FormatTest, FormatsExternC) {
" int i = 42;\n"
" return i;\n"
"}");
+ verifyFormat(
+ "extern \"C\" char const *const\n"
+ " OpenCL_source_OpenCLRunTime_test_attribute_opencl_unroll_hint;");
FormatStyle Style = getLLVMStyle();
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
``````````
</details>
https://github.com/llvm/llvm-project/pull/128817
More information about the cfe-commits
mailing list