[PATCH] D88956: [clang-format] Fix misformatted macro definitions after D86959

Alexander Richardson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 04:33:33 PDT 2020


arichardson created this revision.
arichardson added reviewers: MyDeveloperDay, sammccall, klimek, JakeMerdichAMD, curdeius.
Herald added subscribers: cfe-commits, jfb.
Herald added a project: clang.
arichardson requested review of this revision.

After D86959 <https://reviews.llvm.org/D86959> the code `#define lambda [](const decltype(x) &ptr) {}`
was formatted as `#define lambda [](const decltype(x) & ptr) {}` due to
now parsing the '&' token as a BinaryOperator. The problem was caused by
the condition `Line.InPPDirective && (!Left->Previous || !Left->Previous->is(tok::identifier))) {`
being matched and therefore not performing the checks for "previous token
is one of decltype/_Atomic/etc.". This patch moves those checks after the
existing if/else chain to ensure the left-parent token classification is
always run after checking whether the contents of the parens is an
expression or not.

This change also introduces a new helper function ::annotate() in FormatTest
that returns a list of Tokens after analyzing them. This is used to check
for TT_PointerOrReference, in addition to indirectly testing this based
on the resulting formatting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88956

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TestLexer.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88956.296639.patch
Type: text/x-patch
Size: 9745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201007/4153e5c6/attachment-0001.bin>


More information about the cfe-commits mailing list