[clang-format] Correctly annotate operator free function call
authorEmilia Kond <emilia@rymiel.space>
Thu, 29 Jun 2023 16:46:04 +0000 (19:46 +0300)
committerEmilia Kond <emilia@rymiel.space>
Thu, 29 Jun 2023 16:51:27 +0000 (19:51 +0300)
commit4986f3f2f220e4fd2fef4b08e550b399c9f45a9f
treea262f181e86da0c179bad76adf6e96a68cfad8fc
parente8fcc475580a3fc9927e76cffe5d8d8b368d6830
[clang-format] Correctly annotate operator free function call

The annotator correctly annotates an overloaded operator call when
called as a member function, like `x.operator+(y)`, however, when called
as a free function, like `operator+(x, y)`, the annotator assumed it was
an overloaded operator function *declaration*, instead of a call.

This patch allows for a free function call to correctly be annotated as
a call, but only if the current like cannot be a declaration, usually
within the bodies of a function.

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

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay, Nuullll

Differential Revision: https://reviews.llvm.org/D153798
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp