Skip to content

Fix dangling string_view in rfl::internal::get_type_name_str_view - #804

Merged
liuzicheng1987 merged 1 commit into
munich-data-engineering:mainfrom
clockblocker:fix-get-type-name-str-view
Nov 29, 2026
Merged

liuzicheng1987 merged 1 commit into
munich-data-engineering:mainfrom
clockblocker:fix-get-type-name-str-view

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a regression introduced in 433795b44 (v0.26.1) where rfl::internal::get_type_name_str_view<T>() returns a std::string_view pointing into the destroyed by-value StringLiteral<N> temporary returned by get_type_name<T>():

// Before: dangles into temporary StringLiteral<N> and fails constant evaluation
template <class T>
consteval auto get_type_name_str_view() {
  return get_type_name<T>().string_view();
}

Instead, get_type_name_str_view<T>() now delegates directly to cpp20::get_type_name_str_view<T>() / cpp26::get_type_name_str_view<T>(), returning a view into static storage (__PRETTY_FUNCTION__ / __FUNCSIG__ or std::meta::display_string_of).

Downstream impact

Downstream consumers calling rfl::internal::get_type_name_str_view<T>() in constexpr contexts fail to compile against v0.26.1+—for example, NVIDIA/cuda-quantum in cudaq/lib/Target/Reflection.h L29–L31:

template <typename T>
constexpr std::string_view qualifiedName =
    rfl::internal::get_type_name_str_view<T>();

Key details

  • Adds cpp26::get_type_name_str_view<T>() and builds cpp26::get_type_name<T>() on top of it, matching the existing cpp20 split.
  • Adds static_assert and runtime regression tests in tests/json/test_regression_bugs.cpp.

AI-authored.

clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 29, 2026
Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
@liuzicheng1987

Copy link
Copy Markdown
Collaborator

@clockblocker thank you. I am merging.

@liuzicheng1987
liuzicheng1987 merged commit 08696bd into munich-data-engineering:main Nov 29, 2026
176 checks passed
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Nov 30, 2026
Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Dec 1, 2026
Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
clockblocker added a commit to clockblocker/reflect-cpp that referenced this pull request Dec 2, 2026
Exposes `rfl::type_name<T>()` and `rfl::type_name_v<T>` via a thin,
self-contained public header (`<rfl/type_name.hpp>`, mirroring `<rfl/num_fields.hpp>`
from munich-data-engineering#451/munich-data-engineering#465) returning a compile-time `std::string_view` directly from
`rfl::internal::get_type_name_str_view<T>()` without instantiating
`rfl::Literal` or `rfl::internal::StringLiteral`.

Parent: depends on `fix(reflection): fix dangling string_view in rfl::internal::get_type_name_str_view`
(open upstream PR munich-data-engineering#804).

Judge polish applied:
- Drops redundant `rfl::num_fields_v<T>` (`rfl::num_fields<T>` is already a
  public variable template since munich-data-engineering#465).
- Uses munich-data-engineering#804's `internal::get_type_name_str_view<T>()` directly to avoid
  `StringLiteral<N>` / `make_index_sequence<N>` bloat.

Precedent: munich-data-engineering#451
Downstream receipts:
- NVIDIA/cuda-quantum calls private `rfl::internal::get_type_name_str_view<T>()`
  with comment "Unfortunately, this has to use a private API of reflect-cpp":
  https://github.com/NVIDIA/cuda-quantum/blob/81ef20d9d4a1e0912a6dbc68637ece017e8fd324/cudaq/lib/Target/Reflection.h#L27-L31
- munich-data-engineering/sqlgen hand-rolled `sqlgen::internal::get_type_name_str_view`:
  https://github.com/munich-data-engineering/sqlgen/blob/265b0a174b661c5905b874f97b064aecb4cded70/include/sqlgen/internal/get_type_name.hpp#L13-L44
- games-on-whales/wolf instantiates `rfl::type_name_t<...>().str()`:
  https://github.com/games-on-whales/wolf/blob/ac2461f68feda41fdc7a7c8e812b9ab4b80520b7/src/moonlight-server/api/api.cpp#L26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants