llms.txt: machine-readable documentation index. Markdown version of this page is also available.

CLion 2026.3 Help

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 an std::meta::info value: ^^Widget.

  • A splicer [: :] turns an std::meta::info value back into a type, a value, or a member reference: [:widget_type:].

  • A template for statement 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

  1. Use GCC 16.1 or later. GCC provides reflection as an experimental feature behind the -freflection compiler 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.

  2. Go to Settings | Build, Execution, Deployment | Toolchains and point the C Compiler and C++ Compiler fields of a toolchain to your GCC 16 binaries. For more details, refer to Compilers.

  3. Select that toolchain in the Toolchain field of your CMake profile.

2. Set the language standard and the compiler option

  1. In a CMake project, set the language standard and add -freflection to 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)
  2. 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:

CLion editor with a C++26 sample where the reflection operator, a splicer, and a template for statement are highlighted.

The following sample walks over the data members of any aggregate and prints their names and values:

#include <meta> #include <print> struct Config { int retries; double timeout; }; template <typename T> void print_fields(const T &value) { constexpr auto ctx = std::meta::access_context::unchecked(); template for (constexpr auto member : std::define_static_array( std::meta::nonstatic_data_members_of(^^T, ctx))) { std::println("{} = {}", std::meta::identifier_of(member), value.[:member:]); } } int main() { print_fields(Config{.retries = 3, .timeout = 1.5}); }

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:

Editor with the caret at an opening splicer delimiter and both the opening and the closing delimiter highlighted.

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 ^^Widget and ^^Widget::id as 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:

    Quick documentation popup on a splicer showing the reflection constant it resolves to and its evaluated value.

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:

Editor tooltip reporting a failed static_assert, with the std::meta query already replaced by its 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.

Alongside P2996, which adds reflection itself, CLion supports the proposals that build on it:

  • P1306, expansion statements (template for).

  • P3289, consteval blocks.

  • P3394, annotations for reflection. Annotations written as [[=Value{}]] are parsed, and std::meta::annotations_of queries over them are evaluated.

  • P3293, splicing a base class subobject.

Limitations

  • CLion evaluates the std::meta functions that reflection code relies on most, such as type_of, nonstatic_data_members_of, and define_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.

17 November 2026