[clang] 923c375 - [clang-format] Don't break semi after requires clause ...

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 22 13:09:16 PST 2022


Author: Björn Schäpers
Date: 2022-02-22T22:08:03+01:00
New Revision: 923c3755ea809275d6c06caf547525452568eb5f

URL: https://github.com/llvm/llvm-project/commit/923c3755ea809275d6c06caf547525452568eb5f
DIFF: https://github.com/llvm/llvm-project/commit/923c3755ea809275d6c06caf547525452568eb5f.diff

LOG: [clang-format] Don't break semi after requires clause ...

..regardless of the chosen style.

Fixes https://github.com/llvm/llvm-project/issues/53818

Differential Revision: https://reviews.llvm.org/D120278

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 7649263a18a1e..42c271f35be44 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3963,7 +3963,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
       return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
     return Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes;
   }
-  if (Left.ClosesRequiresClause) {
+  if (Left.ClosesRequiresClause && Right.isNot(tok::semi)) {
     switch (Style.RequiresClausePosition) {
     case FormatStyle::RCPS_OwnLine:
     case FormatStyle::RCPS_WithPreceding:

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 7d8b74c9c455f..98a0111d1ea40 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23861,6 +23861,11 @@ TEST_F(FormatTest, RequiresClausesPositions) {
                "}",
                Style);
 
+  verifyFormat("template <typename T>\n"
+               "int bar(T t)\n"
+               "  requires F<T>;",
+               Style);
+
   Style.IndentRequiresClause = false;
   verifyFormat("template <typename T>\n"
                "requires F<T>\n"
@@ -23881,6 +23886,7 @@ TEST_F(FormatTest, RequiresClausesPositions) {
   verifyFormat("template <typename T> requires Foo<T> struct Bar {};\n"
                "template <typename T> requires Foo<T> void bar() {}\n"
                "template <typename T> void bar() requires Foo<T> {}\n"
+               "template <typename T> void bar() requires Foo<T>;\n"
                "template <typename T> requires Foo<T> Bar(T) -> Bar<T>;",
                Style);
 
@@ -23933,6 +23939,9 @@ TEST_F(FormatTest, RequiresClausesPositions) {
                "void bar()\n"
                "requires Foo<T> {}\n"
                "template <typename T>\n"
+               "void bar()\n"
+               "requires Foo<T>;\n"
+               "template <typename T>\n"
                "requires Foo<T> Bar(T) -> Bar<T>;",
                Style);
 
@@ -23992,6 +24001,7 @@ TEST_F(FormatTest, RequiresClausesPositions) {
                "template <typename T>\n"
                "void bar() requires Foo<T>\n"
                "{}\n"
+               "template <typename T> void bar() requires Foo<T>;\n"
                "template <typename T> requires Foo<T>\n"
                "Bar(T) -> Bar<T>;",
                Style);


        


More information about the cfe-commits mailing list