[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 3 07:29:46 PST 2024


ilya-biryukov wrote:

> can you also add a test to clang/unittests/Format/TokenAnnotatorTest.cpp that ensures trailing attribute-like macros receive `StartOfName` annotation to make sure we don't regress the signal in the future?

ok, that opened a whole can of worms.
```
 Tokens = annotate("void foo GUARDED_BY(x)");
```
gets annotated as
```
{(void, "void" , Unknown),
  (identifier, "foo" , StartOfName),
  (identifier, "GUARDED_BY" , FunctionDeclarationName),
  (l_paren, "(" , Unknown),
  (identifier, "x" , Unknown),
  (r_paren, ")" , Unknown),
  (eof, "" , Unknown)}
```


I expected to get some heuristics for attributes, but instead `GUARDED_BY` gets annotated as a function declaration name.\
It feels that the current behavior is a result of two mistakes cancelling each other out. I don't think adding a unit test like this is warranted, even if formatting behavior is actually correct.

@owenca what are your thoughts on this change and whether we should add a test here?

https://github.com/llvm/llvm-project/pull/76804


More information about the cfe-commits mailing list