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 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

  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

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:

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.

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:

#include <meta> #include <string> #include <string_view> enum class filter { always, only_positive }; struct presentation_opts { filter mode; }; constexpr std::string format(int value) { if (value < 0) return "-" + format(-value); if (value < 10) return std::string(1, char('0' + value)); return format(value / 10) + char('0' + value % 10); } consteval bool filter_out_negative(std::meta::info member) { for (auto annotation : std::meta::annotations_of_with_type(member, ^^presentation_opts)) if (std::meta::extract<presentation_opts>(annotation).mode == filter::only_positive) return true; return false; } template <typename T> constexpr std::string format(const T &value) { std::string out; if (std::meta::has_identifier(^^T)) out += std::meta::identifier_of(^^T); out += '{'; bool first = true; auto delim = [&] { if (!first) out += ", "; first = false; }; constexpr auto ctx = std::meta::access_context::unchecked(); template for (constexpr auto base : std::define_static_array(std::meta::bases_of(^^T, ctx))) { delim(); out += format(static_cast<const [:std::meta::type_of(base):] &>(value)); } template for (constexpr auto member : std::define_static_array(std::meta::nonstatic_data_members_of(^^T, ctx))) { if constexpr (filter_out_negative(member)) { if (value.[:member:] < 0) continue; } delim(); out += '.'; out += std::meta::identifier_of(member); out += '='; out += format(value.[:member:]); } out += '}'; return out; } struct B { int m0 = 0; }; struct X : B { int m1 = +1; }; struct Y : B { int m2 = -2; }; struct Z : X, Y { [[=presentation_opts{filter::only_positive}]] int m3; [[=presentation_opts{filter::only_positive}]] int m4; [[=presentation_opts{filter::always}]] int m5; struct { int m6 = 6, m7 = 7; } nested; }; constexpr auto result = std::meta::reflect_constant_string(format(Z{.m3 = -3, .m4 = 4, .m5 = -5})); using namespace std::string_view_literals; static_assert([:result:] == "Z{X{B{.m0=0}, .m1=1}, Y{B{.m0=0}, .m2=-2}, .m4=4, .m5=-5, .nested={.m6=6, .m7=7}}"sv);

Parsing and highlighting

CLion parses and highlights the reflection operator, splicers, and consteval blocks.

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

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.

20 November 2026