Skip to content

API/Reflection: no public pointer-to-member (&T::field) name reflection API forces duplicate compiler-specific __PRETTY_FUNCTION__/__FUNCSIG__ parsing #177

Not planned

Description

@clockblocker

Part of #138
Popularity: 1/7 corpus consumers (sqlgen)

Related issues

Complements #145 (type-name reflection) in reflect-cpp's compile-time reflection helper surface.

Problem

reflect-cpp reflects aggregate struct field names only at the whole-struct level (rfl::named_tuple_t<T>, rfl::fields<T>(), rfl::to_view). It provides no public compile-time helper to extract the name of a single field from a pointer-to-member non-type template parameter (&Struct::member).

Downstream libraries building type-safe query DSLs, patch/diff builders, or field-selector APIs using pointer-to-member syntax (col<&Person::age>) are forced to re-implement compiler-specific <source_location> / __FUNCSIG__ / __PRETTY_FUNCTION__ parsing across Clang, GCC, and MSVC.

Observed Downstream Workaround

munich-data-engineering/sqlgen (265b0a17)

  • Added in commit 6097e88 ("Added support for the member pointer syntax (API/Defaults & Wrappers: all-or-nothing DefaultIfMissing and intrusive metadata wrappers force shadow structs, .value().value_or() churn, and drift static_asserts #147)"), include/sqlgen/internal/get_member_ptr_name.hpp#L15-L70 duplicates compiler-specific function-signature slicing and then packs the result back into rfl::internal::StringLiteral so it can interoperate with rfl::Field, rfl::Literal, and rfl::field_type_t:
    template <class T, auto ptr>
    consteval auto get_member_ptr_name_str_view() {
    #if __cpp_lib_source_location >= 201907L
      const auto func_name =
          std::string_view{std::source_location::current().function_name()};
    #elif defined(_MSC_VER)
      const auto func_name = std::string_view{__FUNCSIG__};
    #else
      const auto func_name = std::string_view{__PRETTY_FUNCTION__};
    #endif
    #if defined(__clang__)
      const auto split = func_name.substr(0, func_name.size() - 1);
      return split.substr(split.find_last_of(":.") + 1);
    #elif defined(__GNUC__)
      const auto split = func_name.substr(0, func_name.size() - 1);
      return split.substr(split.find_last_of(":.") + 1);
    #elif defined(_MSC_VER)
      auto split = func_name.substr(0, func_name.size() - 7);
      auto pos = split.find_last_of(":");
      if (pos != std::string_view::npos) {
        return split.substr(pos + 1);
      }
      return split;
    #else
      static_assert(
          false,
          "You are using an unsupported compiler. Please use GCC, Clang "
          "or MSVC or explicitly tag your structs using 'Tag' or 'Name'.");
    #endif
    }
    (Note lines L41-L44 even retain reflect-cpp's verbatim unsupported-compiler error message referencing 'Tag' or 'Name', confirming it was adapted directly from reflect-cpp's internal reflection machinery.)
  • Consumed in include/sqlgen/col.hpp#L259-L278 to power sqlgen::col<&Person::age>.

Root Cause in reflect-cpp & Suggested Direction

reflect-cpp already owns and maintains the cross-compiler signature-parsing machinery for Clang, GCC, AppleClang, and MSVC (and will eventually back it with C++26 reflection). Exposing a public consteval pointer-to-member name helper — e.g., rfl::field_name<&T::m>() / rfl::field_name_v<&T::m> returning constexpr std::string_view (and/or a public rfl::StringLiteral variant) — would eliminate duplicated brittle compiler #ifdefs in downstream reflection consumers.

Activity

  1. added
    enhancement
    needs-triage
    known-downstream-workarounds
    on Nov 29, 2026
  2. added
    wontfix
    and removed
    needs-triage
    on Nov 29, 2026
  3. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Triage decision: closing as wontfix (not planned) for the upstream adoption track.

    Rationale: sqlgen-only internal reflection primitive (member-pointer &T::field name extraction). sqlgen is authored by reflect-cpp's own maintainer; if this primitive is wanted in rfl, he can promote it directly without an external PR. Zero external adoption leverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementknown-downstream-workaroundswontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions