[clang-format] Treats &/&& as reference when followed by ',' or ')'
authorMicah Weston <micahsweston@gmail.com>
Sat, 12 Nov 2022 08:51:35 +0000 (00:51 -0800)
committerOwen Pan <owenpiano@gmail.com>
Sat, 12 Nov 2022 08:58:58 +0000 (00:58 -0800)
commite864ac694540342d5e59f59c525c5082f2594fb8
tree7b8cdf0fa453370a4d6b991c24aa14affcfb2824
parent96e23906b5e80dc86b5d2431d30c9afc38ae4d20
[clang-format] Treats &/&& as reference when followed by ',' or ')'

Ran into an issue where function declarations inside function
scopes or uses of sizeof inside a function would treat the && in
'sizeof(Type &&)' as a binary operator.

Attempt to fix this by assuming reference when followed by ',' or
')'. Also adds tests for these.

Also hit an edge case in another test that treated "and" the same
as "&&" since it parses as C++. Changed the "and" to "also" so it
is no longer a keyword.

Fixes #58923.

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