Skip to content

Commit d29a1be

Browse files
authored
[clang-format] Don't break before *const (#128817)
Fixes #28919
1 parent 2d585cc commit d29a1be

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6196,7 +6196,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
61966196
return Line.IsMultiVariableDeclStmt ||
61976197
(getTokenPointerOrReferenceAlignment(Right) ==
61986198
FormatStyle::PAS_Right &&
6199-
(!Right.Next || Right.Next->isNot(TT_FunctionDeclarationName)));
6199+
!(Right.Next &&
6200+
Right.Next->isOneOf(TT_FunctionDeclarationName, tok::kw_const)));
62006201
}
62016202
if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
62026203
TT_ClassHeadName, tok::kw_operator)) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4642,6 +4642,9 @@ TEST_F(FormatTest, FormatsExternC) {
46424642
" int i = 42;\n"
46434643
" return i;\n"
46444644
"}");
4645+
verifyFormat(
4646+
"extern \"C\" char const *const\n"
4647+
" OpenCL_source_OpenCLRunTime_test_attribute_opencl_unroll_hint;");
46454648

46464649
FormatStyle Style = getLLVMStyle();
46474650
Style.BreakBeforeBraces = FormatStyle::BS_Custom;

0 commit comments

Comments
 (0)