Support for C++26 reflection
Reflection was added to the C++26 standard by the P2996 proposal. It lets you query program entities such as types, data members, and enumerators while the program is compiled, and then put the results back into the code.
Reflection adds the following syntax:
The reflection operator
^^turns an entity into anstd::meta::infovalue:^^Widget.A splicer
[: :]turns anstd::meta::infovalue back into a program entity, such as a type or a value:[:widget_type:].A consteval block runs code during compilation outside of a function body.
The reflection queries themselves come from the <meta> standard header.
Configure reflection support
1. Set up the compiler
Use GCC 16.1 or later. GCC provides reflection as an experimental feature behind the
-freflectioncompiler option, which you pass together with-std=c++26. You can check the state of a particular C++26 feature in C++ standards support in GCC.Go to and point the C Compiler and C++ Compiler fields of a toolchain to your GCC 16 binaries. For more details, refer to Compilers.
Select that toolchain in the Toolchain field of your CMake profile.
2. Set the language standard and the compiler option
In a CMake project, set the language standard and add
-freflectionto the target:set(CMAKE_CXX_STANDARD 26) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(reflection_demo main.cpp) target_compile_options(reflection_demo PRIVATE -freflection)Reload the CMake project so that CLion picks up the new compiler and options. For more details, refer to Quick CMake tutorial.
Code insight for reflection
Compile-time evaluation
CLion evaluates reflection code while you type, the same way the compiler does during compilation. It computes the results of ^^ and the std::meta queries and splices them back into the code. As a result, static_assert declarations and consteval blocks that depend on reflection are checked in the editor, before you build the project.
If an assumption is wrong, CLion reports the failed static_assert together with the computed value:

The same evaluation covers code generation: CLion resolves the members that std::meta::define_aggregate adds to an incomplete type, so the code that uses those generated members is analyzed without errors.
Example: format an object at compile time
In the following sample, format() builds a string representation of an object at compile time. It walks over the base classes and the data members of the type, reads the annotations of each member to decide whether to skip a negative value, and calls itself recursively for base classes and nested objects. The static_assert at the end compares the result with the expected string, and CLion evaluates the whole chain to check it:
Parsing and highlighting
CLion parses and highlights the reflection operator, splicers, and consteval blocks.

Limitations
CLion evaluates the
std::metafunctions that reflection code relies on most, such astype_of,nonstatic_data_members_of, anddefine_aggregate. The more specialized functions of the<meta>header are not evaluated yet.Code completion inside reflection contexts is basic and does not cover every position where a reflection or a splicer is allowed.