[clang] [clang-format] Add first support for reflection (PR #193794)

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 26 22:22:22 PDT 2026


owenca wrote:

> > 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).

Still, formatting spaces before `[:` (and within `[:` and `:]`) is just a nice feature/option to have.

> > > 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.

But that wouldn't be an issue unless it's a `.h` file, and the user can add `// clang-format Language: Cpp` at the top of the file instead. We can also add the option mentioned [here](https://github.com/llvm/llvm-project/issues/191295#issuecomment-4228702589) if there's a strong demand.

> 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.

We don't need to wait for clang to catch up with gcc, but I do think we should wait at least until clang lexer implements the splicers. (Maybe @AaronBallman knows when it might happen?)

If you can't wait, you may want to have a look at the [Bloomberg version](https://github.com/bloomberg/clang-p2996/blob/9ffb96e3ce362289008e14ad2a79a249f58aa90a/clang/lib/Lex/Lexer.cpp#L4070) and see if you can get it merged into llvm main branch sooner.

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


More information about the cfe-commits mailing list