[clang-format] Don't break before *const (#128817)
Fixes #28919
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 2ffaee9..3a49650 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -6196,7 +6196,8 @@
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 44209dd..537be36 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4642,6 +4642,9 @@
" 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;