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

Emilia Kond via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 28 07:53:26 PDT 2023


rymiel 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;
----------------
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


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