[clang] [clang-format] Make some binary operations imply requires clause (PR #110942)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 23:59:21 PDT 2024


================
@@ -3528,6 +3528,17 @@ bool UnwrappedLineParser::parseRequires() {
         return false;
       }
       break;
+    case tok::equalequal:
+    case tok::greaterequal:
+    case tok::lessequal:
+    case tok::r_paren:
+    case tok::pipepipe:
+      if (OpenAngles == 0) {
+        FormatTok = Tokens->setPosition(StoredPosition);
+        parseRequiresClause(RequiresToken);
+        return true;
+      }
+      break;
----------------
owenca wrote:

Instead, how about just moving `case tok::amp:` up?
```
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3474,10 +3474,10 @@ bool UnwrappedLineParser::parseRequires() {
   case tok::r_paren:
   case tok::kw_noexcept:
   case tok::kw_const:
+  case tok::amp:
     // This is a requires clause.
     parseRequiresClause(RequiresToken);
     return true;
-  case tok::amp:
   case tok::ampamp: {
     // This can be either:
     // if (... && requires (T t) ...)
```
The rationale is that it doesn't make sense to bitwise-and another expression with a `requires` expression.

https://github.com/llvm/llvm-project/pull/110942


More information about the cfe-commits mailing list