Building a C++ Reflection System in One Weekend Using Clang and LLVM
summary
Builds a runtime C++ reflection system over a weekend using Clang LibTooling and LLVM that parses ASTs, matches classes/fields annotated with an attribute, and generates C++ source (a .generated.h) to include in the program. Handles primitives plus special-case implementations for std::string and std::vector, emits offsets and type hashes for safe JSON (de)serialization, and can invoke reflected functions with trampoline tricks. AST dumps hit ~106k lines with >2k records and ~1k fields; implementation is working and published as metareflect on GitHub.
AI-written summary · about
chapters (14)
- 0:00Introduction to reflection
- 1:47Problems with manual serialization
- 3:56C# reflection capabilities
- 6:49Translating to C++ reflection
- 9:04Designing the reflection API
- 12:42Handling primitive types
- 14:54Type dispatch for templates
- 16:18Automating reflection with LLVM
- 21:14Annotating classes for reflection
- 24:50Generating reflection code
- 29:28Demo of generated reflection
- 33:12Future improvements and optimizations
- 35:20Implementation details
- 38:39Q&A session
related talks
01h 37mReflection: Compile-Time Introspection of C++
01h 01mReflection
01h 08mReflections: Compile-time Introspection of Source Code
05mC++ Reflection via Clang LibTooling
01h 10mReflection Is Good for C++ Code Health
36mCompile-time reflection, Serialization and ORM
01h 18mReflection API for Modern C++
01h 08mKeynote: Reflection in C++26 - Welcome to v0.1 of the meta::[[verse]]!
