Skip to content

Simple tests for supported special member functions - #126

Open
jbcoe wants to merge 13 commits into
mainfrom
reflection-impl/supported-special-members
Open

Simple tests for supported special member functions#126
jbcoe wants to merge 13 commits into
mainfrom
reflection-impl/supported-special-members

Conversation

@jbcoe

@jbcoe jbcoe commented Aug 7, 2026

Copy link
Copy Markdown
Owner

First step in adding a reflection-based implementation of protocol (and protocol_view).

No reflection features are currently needed, just C++ 20 concepts and requirement checks to conditionally generate constructors.

Once this is landed we can extend the tests to document and test-drive a full implementation.

GTEST_SKIP() << "Skipping test"; can be used to skip tests while we are waiting to add implementation support.

Once a complete implementation has been submitted, we can retire the Python implementation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces an initial “reflection” scaffold for protocol / protocol_view, focused on compile-time constraints for special member functions and accompanying tests as a foundation for a future reflection-based implementation.

Changes:

  • Adds xyz::reflection::protocol and xyz::reflection::protocol_view declarations with constrained special member functions.
  • Adds GoogleTest-based compile-time trait checks documenting expected special-member availability.
  • Wires the new reflection header + tests into the CMake build when testing is enabled.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
reflection/protocol.h Adds initial reflection-based protocol/protocol_view declarations (currently header-only).
reflection/protocol_test.cc Adds compile-time tests asserting special member function support expectations.
reflection/CMakeLists.txt Defines an INTERFACE target for the reflection header and a test target.
CMakeLists.txt Adds the reflection subdirectory to the test-enabled build configuration.
Suppressed comments (4)

reflection/protocol_test.cc:26

  • Test suite name abbreviates “Reflection” as “R”, but the project guidelines require avoiding abbreviations in names. Consider using a fully spelled-out suite name.
TEST(RProtocolViewTest, CheckSpecialMembersForStructWithDeletedSpecialMembers) {

reflection/protocol_test.cc:46

  • Test suite name abbreviates “Reflection” as “R”, but the project guidelines require avoiding abbreviations in names. Consider using a fully spelled-out suite name.
TEST(RProtocolTest, CheckSpecialMembers) {

reflection/protocol_test.cc:58

  • Test suite name abbreviates “Reflection” as “R”, but the project guidelines require avoiding abbreviations in names. Consider using a fully spelled-out suite name.
TEST(RProtocolTest, CheckSpecialMembersForStructWithDeletedSpecialMembers) {

reflection/protocol_test.cc:60

  • In these comments, “deleted” is misleading (objects are destroyed/destructed, not “deleted”). Consider rewording to avoid confusion about dynamic allocation.
  // protocol is not default-constructible and cannot be copied, moved,
  // assigned, move assigned and deleted if the underlying type cannot be.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread reflection/protocol.h
Comment thread reflection/protocol.h
Comment thread reflection/protocol_test.cc Outdated
Comment thread reflection/protocol.h
Comment thread reflection/protocol_test.cc Outdated
Comment thread reflection/protocol_test.cc Outdated
@jbcoe

jbcoe commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

@copilot Fix the failing tests by restoring the missing definition of struct A {};

Copilot AI commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@copilot Fix the failing tests by restoring the missing definition of struct A {};

Addressed in 468b4c6. struct A {} is restored at local scope in the tests that use it, and the branch now builds and tests cleanly.

@jbcoe
jbcoe marked this pull request as ready for review August 8, 2026 13:13
@jbcoe
jbcoe requested review from RyanJK5 and Twon August 8, 2026 13:13

@RyanJK5 RyanJK5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall 👍

Comment thread reflection/protocol.h Outdated
class protocol {
public:
// Special member functions.
protocol() = delete;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does an interface with a defaulted copy constructor imply the protocol object should be default constructible? e.g.

struct I {
    I() = default;
};

protocol<I> p{}; // Now has a valid empty state

I thought I noticed something like that in the original implementation, but I may very well be mistaken.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a rethink but for now I think should be suppressed.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking here is that for polymorphic, interfaces are often pure virtual whereas the design of protocol is to use structs without implementations of functions. Requiring the user to explicitly delete default construction seems unhelpful and later constructors (in place type) will allow construction from any conformant type.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, and also possible to change later if need be. It would also complicate matters, since in the default constructor case, valueless_after_move would be a misnomer (it could have been empty because it was constructed that way). duck similarly avoids the complexity by disallowing default construction.

Comment thread reflection/protocol.h Outdated
Comment thread reflection/protocol.h Outdated
@jbcoe
jbcoe marked this pull request as draft August 9, 2026 07:17
@jbcoe

jbcoe commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@copilot look at https://eel.is/c++draft/mem.composite.types and update protocol constructor requirements to model the class template polymorphic

@RyanJK5

RyanJK5 commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

I also pushed a change to add noexcept to protocol_view's move constructor and assignment, I can roll it back if that's unwanted. I withheld adding it to protocol since according to my understanding, that will depend on how the allocator type specifies POCMA and is_always_equal.

@jbcoe

jbcoe commented Aug 10, 2026

Copy link
Copy Markdown
Owner Author

@RyanJK5 Looks good. As a first step this is easy to approve. We can fine-tune in later PRs.

@jbcoe
jbcoe force-pushed the reflection-impl/supported-special-members branch from 13452bb to beb5b1e Compare August 10, 2026 06:16
Comment thread reflection/CMakeLists.txt
ALIAS xyz_protocol::reflection_protocol)
target_sources(
reflection_protocol INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/protocol.h>)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding ${CMAKE_CURRENT_SOURCE_DIR} to files in the current directory is only necessary for CMake version proior to 3.13, for details see: https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/

Suggested change
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/protocol.h>)
$<BUILD_INTERFACE:protocol.h>)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The amended code gives me

CMake Error in reflection/CMakeLists.txt:
  Target "reflection_protocol" contains relative path in its
  INTERFACE_SOURCES:

    "protocol.h"

We've used the same pattern in CMakeLists.txt at the project root. Perhaps they can all be cleaned up in sync later?

Comment thread reflection/CMakeLists.txt
Comment thread reflection/protocol_test.cc Outdated

@Twon Twon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments but otherwise looks good

jbcoe and others added 6 commits August 11, 2026 16:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 5 commits August 11, 2026 16:01
Co-authored-by: jbcoe <777363+jbcoe@users.noreply.github.com>
Co-authored-by: jbcoe <777363+jbcoe@users.noreply.github.com>
Co-authored-by: jbcoe <777363+jbcoe@users.noreply.github.com>
@jbcoe
jbcoe force-pushed the reflection-impl/supported-special-members branch from beb5b1e to 341e171 Compare August 11, 2026 15:01
@jbcoe
jbcoe marked this pull request as ready for review August 11, 2026 20:49
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.

5 participants