[clang-format] Don't allow variable decls to have trailing return arrows
authorEmilia Dreamer <emilia@rymiel.space>
Mon, 3 Apr 2023 12:54:17 +0000 (15:54 +0300)
committerEmilia Dreamer <emilia@rymiel.space>
Mon, 3 Apr 2023 12:54:21 +0000 (15:54 +0300)
commitfd86789962964a98157e8159c3d95cdc241942e3
treee1b881f7ac7dd4c3db180eb7e5a8e60f82d47c9d
parentb58a697f3e19437f8525ec31a384c8901b0b736c
[clang-format] Don't allow variable decls to have trailing return arrows

The heuristic for determining if an arrow is a trailing return arrow
looks for the auto keyword, along with parentheses. This isn't
sufficient, since it also triggers on variable declarations with an auto
type, and with an arrow operator.

This patch makes sure a function declaration is being parsed, instead of
any other declaration.

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

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

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