diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index d97f56751ea69..d89d1cdd12c29 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -5854,6 +5854,12 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, // concept ... if (Right.is(tok::kw_concept)) return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always; + if (Style.BreakTemplateDeclarations == FormatStyle::BTDS_Yes && + Right.is(TT_RequiresClause) && + (Style.RequiresClausePosition == FormatStyle::RCPS_WithPreceding || + Style.RequiresClausePosition == FormatStyle::RCPS_SingleLine)) { + return false; + } return Style.BreakTemplateDeclarations == FormatStyle::BTDS_Yes || (Style.BreakTemplateDeclarations == FormatStyle::BTDS_Leave && Right.NewlinesBefore > 0); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d9db06667d802..53b591bf504af 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -10848,6 +10848,14 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { "public:\n" " E *f();\n" "};"); + AlwaysBreak.RequiresClausePosition = FormatStyle::RCPS_SingleLine; + verifyFormat("template requires std::floating_point\n" + "using LerpValue = ClampedValue;", + AlwaysBreak); + AlwaysBreak.RequiresClausePosition = FormatStyle::RCPS_WithPreceding; + verifyFormat("template requires std::floating_point\n" + "using LerpValue = ClampedValue;", + AlwaysBreak); FormatStyle NeverBreak = getLLVMStyle(); NeverBreak.BreakTemplateDeclarations = FormatStyle::BTDS_No;