Skip to content

[WIP] Add stub implementations for interface member functions using C++26 reflection and vanishing-this-pointer - #131

Draft
jbcoe with Copilot wants to merge 3 commits into
mainfrom
copilot/add-stub-implementations
Draft

[WIP] Add stub implementations for interface member functions using C++26 reflection and vanishing-this-pointer#131
jbcoe with Copilot wants to merge 3 commits into
mainfrom
copilot/add-stub-implementations

Conversation

Copilot AI commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Adds member-function-like call syntax to xyz::reflection::protocol<T> and protocol_view<T> via compile-time stub synthesis. The stubs are invocable with the correct signatures; bodies call std::unreachable() pending the vtable dispatch layer.

Approach

Vanishing-this-pointer thunks (reflection/protocol.h): Four thunk templates cover the {const, mutable} × {noexcept, throwing} matrix. Each thunk's operator() mirrors one interface method's exact signature and recovers the enclosing base pointer via static_cast<OwnerBase*>(static_cast<void*>(this)).

Reflection-driven synthesis: A consteval helper (detail::method_thunk_specs) iterates members_of(^^T), builds a function-pointer type R(*)(Args...) per method via substitute, selects the appropriate thunk template, and returns data_member_spec entries. Overloaded names are deduplicated (first declaration wins; a comment describes the encoding approach for a future revision).

define_aggregate in consteval blocks: protocol<T> and protocol_view<T> each inherit from a forward-declared base (protocol_member_stubs<T> / protocol_view_member_stubs<T>) that is completed by a consteval {} block in the class body, injecting one [[no_unique_address]] thunk per method.

struct Interface {
  std::string_view name() const noexcept;
  int count();
};

// Both calls compile with the correct return types and noexcept status.
static_assert(noexcept(std::declval<const protocol<Interface>>().name()));
static_assert(!noexcept(std::declval<protocol<Interface>>().count()));

conforms_to<Interface, Concrete>(): Special member functions are now explicitly skipped (previously relied on has_identifier as an imperfect guard).

Supporting changes

  • reflection/CMakeLists.txt: build target (C++26, -freflection).
  • CMakeLists.txt: XYZ_PROTOCOL_BUILD_REFLECTION_IMPLEMENTATION option with a check_cxx_source_compiles guard; add_subdirectory(reflection) placed inside the BUILD_TESTING block so GTest is available.
  • scripts/cmake.py: --reflection flag; uses setdefault so existing CXX/CC environment variables take precedence over the g++-16 fallback.
  • cmake/xyz_add_test.cmake: added 26 to the list of valid VERSION values.

Copilot AI and others added 2 commits August 8, 2026 17:41
…ng this pointer trick

Co-authored-by: jbcoe <777363+jbcoe@users.noreply.github.com>
…nment handling, and concept name

Co-authored-by: jbcoe <777363+jbcoe@users.noreply.github.com>
Copilot AI changed the title [WIP] Add stub implementations for interface member functions Add stub implementations for interface member functions using C++26 reflection and vanishing-this-pointer Aug 8, 2026
Copilot AI requested a review from jbcoe August 8, 2026 17:44
@jbcoe jbcoe changed the title Add stub implementations for interface member functions using C++26 reflection and vanishing-this-pointer [WIP] Add stub implementations for interface member functions using C++26 reflection and vanishing-this-pointer Aug 9, 2026
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.

Add stub implementations for interface member functions

2 participants