Skip to content

API/Enums & Bundling: <rfl/enums.hpp> leaks bundled enchantum:: namespace (sqlgen directly uses enchantum::ScopedEnum) #189

Not planned

Description

@clockblocker

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

Related issues

Related to #144 (bundled third-party surface in include/rfl/thirdparty — enchantum) and #150 (enum helpers).

Problem

<rfl/enums.hpp> transitively exposes the bundled third-party enchantum:: namespace directly into consumer translation units, while not providing a public rfl:: scoped-enum concept/trait for C++20 consumers (where std::is_scoped_enum_v is not yet available — it was added in C++23).

Downstream libraries that include <rfl/enums.hpp> end up depending directly on enchantum::* symbols, coupling their public headers to reflect-cpp's internal third-party enum backend. This breaks downstream code if reflect-cpp ever isolates/namespaces enchantum, swaps enum backends (e.g., C++26 reflection), or builds against a different external enchantum version via -DREFLECTCPP_USE_BUNDLED_DEPENDENCIES=OFF.

Observed Downstream Workaround

munich-data-engineering/sqlgen (265b0a17)

  • include/sqlgen/duckdb/parsing/Parser_enum.hpp#L6-L23: reaches directly into enchantum::ScopedEnum<EnumT> inside a public sqlgen header:
    #include <rfl.hpp>
    #include <rfl/enums.hpp>
    ...
    template <class EnumT>
      requires std::is_enum_v<EnumT>
    struct Parser<EnumT> {
      using ResultingType = uint8_t;
    
      static_assert(enchantum::ScopedEnum<EnumT>, "The enum must be scoped.");
      static constexpr auto arr = rfl::get_enumerator_array<EnumT>();
      static_assert(arr.size() < 255, "Enum size cannot exceed 255.");

(Additional context relevant to #150: in the same file at include/sqlgen/duckdb/parsing/Parser_enum.hpp#L34-L35, sqlgen calls rfl::enum_to_string(_t) solely to pass .c_str(), .length() to duckdb_append_varchar_length, incurring a per-row std::string allocation because no zero-allocation std::string_view enum lookup exists.)

Root Cause in reflect-cpp & Suggested Direction

  1. <rfl/enums.hpp> lacks C++20 public enum classification traits/concepts (such as rfl::is_scoped_enum_v<T> / rfl::ScopedEnum<T>), nudging consumers who already see enchantum:: in scope to reach directly into the bundled third-party library.
  2. Suggested fix:
    • Provide lightweight public traits in <rfl/enums.hpp> (e.g., rfl::is_scoped_enum_v<E> using std::is_enum_v<E> && !std::is_convertible_v<E, std::underlying_type_t<E>>) so C++20 consumers never need to spell enchantum::*.
    • Consider isolating/vendoring internal third-party headers/namespaces if reflect-cpp plans to swap enum backends in the core rewrite.

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 enchantum::ScopedEnum leak / trait usage. sqlgen is authored by reflect-cpp's own maintainer; if wanted as a public rfl trait or decoupled from enchantum::, he can make that call directly. 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