Summary
In this patch, we fix the misplacement of * in a definition of a pointer to a struct. It's caused by wrong annotating about tokens * and &&.
Issue
The result of echo 'struct { int foo; } *foop;' | clang-format should be
struct { int foo; } *foop;
instead of
struct { int foo; } * foop;
Handle star token (*)
After right braces, star tokens are likely pointers to a struct, union, or class instead of binary operators. In this case, function determineStarAmpUsage should return TT_PointerOrReference.
- example: struct {} *ptr;
Handle ampamp token (&&)
&& tokens, right after right braces, might be references or binary operators. When initializing references to a struct, union, or class, && are references. When utilized in templates, && are likely binary operators. So we check whether there is a TemplateCloser(">") to indicate it's a template or not. If it's a template, && is a binary operator; on the other hand, if not, it is likely a reference operator.
- reference operator case: struct {} &&ptr={};
- binary operator cases: enable_if<>{} && ...
Instead of checking for r_brace, maybe it would be possible to check PrevToken->MatchingParen for being TT_RecordLBrace?
This way, we'd be precise.
WDYT?