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;