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 type, a value, or a member reference:[:widget_type:].A
template forstatement iterates over a sequence that is known at compile time.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
Parsing and highlighting
CLion parses and highlights the reflection operator, splicers, template for statements, and consteval blocks:

The following sample walks over the data members of any aggregate and prints their names and values:
Matching splicer delimiters
When you place the caret next to [: or :], CLion highlights the matching delimiter, the same way it does for braces and parentheses:

Navigation and usages
CLion resolves the operand of ^^ and the expression inside a splicer, so the navigation and search actions work on them:
Go to Declaration (Ctrl+B) from an identifier inside a splicer opens the declaration of the reflection constant that is spliced. From the operand of
^^, it opens the declaration of the reflected entity.Find Usages (Alt+F7) and Highlight Usages in File (Ctrl+Shift+F7) count
^^Widgetand^^Widget::idas usages of the reflected entities.Quick Documentation (Ctrl+Q) on a splicer shows the reflection constant behind it, together with the value that constant evaluates to:

Compile-time evaluation
CLion evaluates the common std::meta queries while you type, which means that static_assert declarations and consteval blocks built on top of them are checked in the editor. A wrong assumption is reported 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.
Related proposals
Alongside P2996, which adds reflection itself, CLion supports the proposals that build on it:
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.