https://github.com/owenca created https://github.com/llvm/llvm-project/pull/128817
Fixes #28919 >From 3ca7f64c1165fbbf93f1715a80b4a9fbbb7d245f Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Tue, 25 Feb 2025 20:43:25 -0800 Subject: [PATCH] [clang-format] Don't break before *const Fixes #28919 --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits