[clang] [clang-format] Add first support for reflection (PR #193794)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 26 12:46:51 PDT 2026
HazardyKnusperkeks wrote:
> > GCC 16 (who's release is imminent) implements all of it (although it still needs to be opted in) and we have an active bug report.
>
> It's not a bug but a feature request as you marked. See also [#192040 (comment)](https://github.com/llvm/llvm-project/issues/192040#issuecomment-4320823241).
Fair, I marked as a feature request, because we didn't have reflection in before. Still real world usage will rise once GCC 16 is released (I include myself into that group).
> > The lexer already gives the `tok::caretcaret` when the option `Reflection` is enabled, so work in clang at least started.
>
> Yeah, but `^^` is an easy one.
>
> > If we get the splicers from the lexer, that would be great, but this works and as soon as they implement it in the lexer the token annotator test fails and I sure hope they either know how to fix that them self or come and ask us.
>
> The reason for waiting for the clang lexer support is that we don't want `FormatTokenLexer` to be burdened with special cases like `[:::foo:]`, `<::foo::>`, `<::::foo::>`, `[[using ns:]]`, etc.
Understandable, but I would just ignore digraphs at this point. I can think of no valid code containing `:]` apart from digraphs and reflection, that only leaves `[::foo]` which can be the index operator with a fully qualified identifier, very simple to detect.
> > It would be a shame if a modern code base will (partially) disable clang-format, just because we detect the code wrongfully as objective c once they start using reflection.
>
> Can you elaborate with an example or a GitHub issue?
I can't. But in the current state there's a good chance that you need `// clang-format off` your reflection code. And when that becomes the case more often one could get annoyed to the point of stopping using clang-format.
I did a quick research and it seems we can be waiting on reflection in clang a bit longer:
* No active PR for reflection
* This thread hasn't been updated since February: https://discourse.llvm.org/t/dedicated-meeting-for-c-26-reflection/88927
I would really like to get clang-format to handle reflection and don't see a big risk in merging the tokens.
https://github.com/llvm/llvm-project/pull/193794
More information about the cfe-commits
mailing list