[clang-format] Detect pointer qualifiers in cast expressions
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fri, 28 Aug 2020 10:03:10 +0000 (11:03 +0100)
committerAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fri, 28 Aug 2020 10:31:47 +0000 (11:31 +0100)
commit96824abe7d80fc499032dab598968436132fcfb5
tree22753ed1e623d01846689c3d596a9091da91226d
parentd304360decefae3fa5c807a8cd0d7d4501a1cc4b
[clang-format] Detect pointer qualifiers in cast expressions

When guessing whether a closing paren is then end of a cast expression also
skip over pointer qualifiers while looking for TT_PointerOrReference.
This prevents some address-of and dereference operators from being parsed
as a binary operator.

Before:
x = (foo *const) * v;
x = (foo *const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified _Nonnull) & v;

After:
x = (foo *const)*v;
x = (foo *const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified _Nonnull)&v;

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D86716
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp