[all-commits] [llvm/llvm-project] 0bf63f: [clang-format] Disallow trailing return arrows to ...

Emilia Dreamer via All-commits all-commits at lists.llvm.org
Sun Sep 18 18:06:29 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0bf63f0d1b6b860a7134d668d3a28104c5c9afc1
      https://github.com/llvm/llvm-project/commit/0bf63f0d1b6b860a7134d668d3a28104c5c9afc1
  Author: Emilia Dreamer <emilia at rymiel.space>
  Date:   2022-09-19 (Mon, 19 Sep 2022)

  Changed paths:
    M clang/lib/Format/TokenAnnotator.cpp
    M clang/unittests/Format/TokenAnnotatorTest.cpp

  Log Message:
  -----------
  [clang-format] Disallow trailing return arrows to be operators

In the following construction:
`template <typename T> requires Foo<T> || Bar<T> auto func() -> int;`

The `->` of the trailing return type was actually considered as an
operator as part of the binary operation in the requires clause, with
the precedence level of `PrecedenceArrowAndPeriod`, leading to fake
parens being inserted in strange locations, that would never be closed.

Fixes one part of https://github.com/llvm/llvm-project/issues/56213
(the rest will probably be in a separate patch)

Reviewed By: HazardyKnusperkeks, owenpan

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


  Commit: 8dab452740007e03c963b349e716068eac2b25a0
      https://github.com/llvm/llvm-project/commit/8dab452740007e03c963b349e716068eac2b25a0
  Author: Emilia Dreamer <emilia at rymiel.space>
  Date:   2022-09-19 (Mon, 19 Sep 2022)

  Changed paths:
    M clang/lib/Format/TokenAnnotator.cpp
    M clang/unittests/Format/TokenAnnotatorTest.cpp

  Log Message:
  -----------
  [clang-format] Disallow requires clauses to become function declarations

There already exists logic to disallow requires *expressions* to be
treated as function declarations, but this expands it to include
requires *clauses*, when they happen to also be parenthesized.

Previously, in the following case:

```
template <typename T>
  requires(Foo<T>)
T foo();
```

The line with the requires clause was actually being considered as the
line with the function declaration due to the parentheses, and the
*real* function declaration on the next line became a trailing
annotation

(Together with https://reviews.llvm.org/D134049) Fixes https://github.com/llvm/llvm-project/issues/56213

Reviewed By: HazardyKnusperkeks, owenpan

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


Compare: https://github.com/llvm/llvm-project/compare/0e43f3b04d52...8dab45274000


More information about the All-commits mailing list