Draft
[WIP] Add stub implementations for interface member functions using C++26 reflection and vanishing-this-pointer#131
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds member-function-like call syntax to
xyz::reflection::protocol<T>andprotocol_view<T>via compile-time stub synthesis. The stubs are invocable with the correct signatures; bodies callstd::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'soperator()mirrors one interface method's exact signature and recovers the enclosing base pointer viastatic_cast<OwnerBase*>(static_cast<void*>(this)).Reflection-driven synthesis: A
constevalhelper (detail::method_thunk_specs) iteratesmembers_of(^^T), builds a function-pointer typeR(*)(Args...)per method viasubstitute, selects the appropriate thunk template, and returnsdata_member_specentries. Overloaded names are deduplicated (first declaration wins; a comment describes the encoding approach for a future revision).define_aggregatein consteval blocks:protocol<T>andprotocol_view<T>each inherit from a forward-declared base (protocol_member_stubs<T>/protocol_view_member_stubs<T>) that is completed by aconsteval {}block in the class body, injecting one[[no_unique_address]]thunk per method.conforms_to<Interface, Concrete>(): Special member functions are now explicitly skipped (previously relied onhas_identifieras an imperfect guard).Supporting changes
reflection/CMakeLists.txt: build target (C++26,-freflection).CMakeLists.txt:XYZ_PROTOCOL_BUILD_REFLECTION_IMPLEMENTATIONoption with acheck_cxx_source_compilesguard;add_subdirectory(reflection)placed inside theBUILD_TESTINGblock so GTest is available.scripts/cmake.py:--reflectionflag; usessetdefaultso existingCXX/CCenvironment variables take precedence over theg++-16fallback.cmake/xyz_add_test.cmake: added26to the list of validVERSIONvalues.