[all-commits] [llvm/llvm-project] 560eb2: [clang-format] Fix bug in parsing `operator<` with...

Jino Park via All-commits all-commits at lists.llvm.org
Wed Jan 19 23:59:21 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 560eb2277bb5aea0982ce5f90321788cda3fe4b3
      https://github.com/llvm/llvm-project/commit/560eb2277bb5aea0982ce5f90321788cda3fe4b3
  Author: Jino Park <pjessesco at gmail.com>
  Date:   2022-01-20 (Thu, 20 Jan 2022)

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

  Log Message:
  -----------
  [clang-format] Fix bug in parsing `operator<` with template

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

This patch handles a bug when parsing a below example code :

```
template <class> class S;

template <class T> bool operator<(S<T> const &x, S<T> const &y) {
  return x.i < y.i;
}

template <class T> class S {
  int i = 42;
  friend bool operator< <>(S const &, S const &);
};

int main() { return S<int>{} < S<int>{}; }
```
which parse `< <>` as `<< >`, not `< <>` in terms of tokens as discussed in discord.

1. Add a condition in `tryMergeLessLess()` considering `operator` keyword and `>`
2. Force to leave a whitespace between `tok::less` and a template opener
3. Add unit test

Reviewed By: MyDeveloperDay, curdeius

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




More information about the All-commits mailing list