[PATCH] D119138: [clang-format] Further improve support for requires expressions

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 12 00:55:55 PST 2022


HazardyKnusperkeks planned changes to this revision.
HazardyKnusperkeks added inline comments.


================
Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2835-2841
+      // FIXME: We need an annotation on the paren to really know if it is a
+      // function call:
+      // ... foo() && requires ...
+      // or a declaration:
+      // void foo() && requires ...
+      // there is no distinction possible right now. We go for the latter,
+      // because it's more likely to appear in code.
----------------
Quuxplusone wrote:
> I think it's weird that your heuristic parses backward rather than forward. I would think that the next token //after// the `requires` keyword tells you what it is with pretty high probability:
> `requires requires` — it's a clause
> `requires identifier` — it's a clause
> `requires {` — it's an expression
> `requires (` — unclear, apply further heuristics
> 
> Or are those heuristics already present in trunk, and this PR is just dealing with the "unclear" case?
That would be so much better, but I can't easily look forward. `Next` is still `nullptr`, until I call `nextToken()`, but then I'm already moved along.

But this got me thinking, at least for the easy stuff I can just go forward and don't start on the keyword in `parseRequiresClause()` and `parseRequiresExpression()`. The paren case is more tricky, but I will try something.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119138/new/

https://reviews.llvm.org/D119138



More information about the cfe-commits mailing list