[PATCH] D153798: [clang-format] Correctly annotate operator free function call

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 01:11:20 PDT 2023


owenpan accepted this revision.
owenpan added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:319
+           Prev->Previous->isOneOf(tok::period, tok::arrow)) ||
+          (!Line.MustBeDeclaration && !Line.InMacroBody);
       Contexts.back().IsExpression = OperatorCalledAsMemberFunction;
----------------
rymiel wrote:
> owenpan wrote:
> > Why not `Line.InMacroBody`? Wouldn't it misformat the following snippet?
> > ```
> > #define FOO           \
> >   void foo() {        \
> >     operator+(a * b); \
> >   }
> > ```
> Yes, but it would break this test case: https://github.com/llvm/llvm-project/blob/e469d0d636f36140b08d0b5f603c043008307bcf/clang/unittests/Format/FormatTest.cpp#L11573
> 
> I understand it's a nasty workaround, though, but it's quick. The other option seems to be rewriting how overloaded operators are annotated to instead be more like regular function declarations, but I haven't gauged how hard that would be
Yeah. Can you add the snippet as a FIXME test case (under `#if 0`)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153798



More information about the cfe-commits mailing list