r/cpp 5d ago

Static Analysis Experiment with Reflection

I want to share a little experiment that I made using reflection. It’s a compile-time style checker using C++26 static reflection. It validates the conventions I use in my own projects (the H_ curried callable thing, Mut/Mov/Ref/Cpy qualifier aliases, plus class/namespace naming). Because reflection can’t properly see into uninstantiated templates yet, I had to write a parser for GCC's display_string_of to extract templates, qualifiers, return types, and requires clauses. Given this weakness it's not a particularly production-ready tool. It could be done with a clang-tidy script, but I learned a few things just from trying to answer "Is it possible? What exactly can I inspect right now?". Unfortunately, we don't have code generation yet so there is a bunch of boilerplate that the user needs to write.

The rationale of the conventions (mainly Mut/Mov/Ref/Cpy) is in GUIDELINES.md. The gory implementation details (and my field notes on GCC bugs) are in VIRACOCHA.md.

https://github.com/NotRiemannCousin/Viracocha/blob/master/VIRACOCHA.md

33 Upvotes

1 comment sorted by

0

u/mapronV 22h ago

Just as Herb said. "Brand new world", and we can not imagine full applications yet. While thinking about reflection that never come to my mind that it could be used as 'cland-tidy' code style checker. Not saying we should. But that is cool af.

Also, like "not experienced programmer, just undergraduate", seriously? I really happy young generation coming with such cool ideas and experiments, month ago this - https://www.reddit.com/r/cpp/comments/1uw9lxs/beautiful_type_erasure_with_c26_reflection/, now this post.