[clang-format] Skip preprocessor lines when finding the record lbrace
authorArthur Eubanks <aeubanks@google.com>
Wed, 13 Apr 2022 21:36:30 +0000 (14:36 -0700)
committerArthur Eubanks <aeubanks@google.com>
Thu, 14 Apr 2022 16:31:15 +0000 (09:31 -0700)
commitf14ebe91c5dd6be5b64a45e479291cd08676be0c
treeb3d9fc193d29d3126417ec7aceee0036ec2f65b1
parenta5a258e208b44508b877e2395df51f92403245b3
[clang-format] Skip preprocessor lines when finding the record lbrace

With D117142, we would now format

```
struct A {
#define A
  void f() { a(); }
#endif
};
```

into

```
struct A {
#ifdef A
  void f() {
    a();
  }
#endif
};
```

because we were looking for the record lbrace without skipping preprocess lines.

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

Reviewed By: curdeius, owenpan

Differential Revision: https://reviews.llvm.org/D123737
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp