Skip to content

Enhance protocol templates for zero-indirection conversions#48

Draft
jbcoe wants to merge 6 commits intomainfrom
jbcoe/view-from-protocol
Draft

Enhance protocol templates for zero-indirection conversions#48
jbcoe wants to merge 6 commits intomainfrom
jbcoe/view-from-protocol

Conversation

@jbcoe
Copy link
Copy Markdown
Owner

@jbcoe jbcoe commented Mar 30, 2026

No description provided.

@jbcoe jbcoe changed the title Enhance protocol view and vtable templates for zero-indirection conve… Enhance protocol templates for zero-indirection conversions Mar 30, 2026
@jbcoe jbcoe requested a review from Copilot March 31, 2026 12:31
Repository owner deleted a comment from Copilot AI Mar 31, 2026

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

};

template <typename T>
inline constexpr protocol_view_dcb_{{ c.name }}<T> protocol_view_dcb_{{ c.name }}_inst{};
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

protocol_view_dcb_{{ c.name }} is a polymorphic type (inherits a class with a virtual destructor), so it is not a literal type. Declaring protocol_view_dcb_{{ c.name }}_inst as inline constexpr will not compile under standard C++ (constexpr variables must have literal type). Consider using inline const (and optionally constinit if constant initialization is required) instead of constexpr for this per-T instance.

Suggested change
inline constexpr protocol_view_dcb_{{ c.name }}<T> protocol_view_dcb_{{ c.name }}_inst{};
inline const protocol_view_dcb_{{ c.name }}<T> protocol_view_dcb_{{ c.name }}_inst{};

Copilot uses AI. Check for mistakes.
};

template <typename T>
inline constexpr protocol_view_const_dcb_{{ c.name }}<T> protocol_view_const_dcb_{{ c.name }}_inst{};
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

protocol_view_const_dcb_{{ c.name }} inherits from protocol_view_const_cb_{{ c.name }} which has a virtual destructor, so this type is also non-literal. The inline constexpr protocol_view_const_dcb_{{ c.name }}_inst variable therefore won’t compile as a constexpr variable. Use inline const (or constinit if you need to guarantee static initialization) instead of constexpr here.

Suggested change
inline constexpr protocol_view_const_dcb_{{ c.name }}<T> protocol_view_const_dcb_{{ c.name }}_inst{};
inline const protocol_view_const_dcb_{{ c.name }}<T> protocol_view_const_dcb_{{ c.name }}_inst{};

Copilot uses AI. Check for mistakes.
}

const protocol_view_cb_{{ c.name }}* xyz_protocol_as_view_cb() const noexcept override {
return const_cast<direct_control_block*>(this);
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

xyz_protocol_as_view_cb() uses const_cast<direct_control_block*>(this) even though the function returns a const pointer and no mutation is needed. This casts away const unnecessarily and can trigger warnings. Returning this (or a static_cast to the appropriate base pointer) preserves const-correctness and still performs the required multiple-inheritance pointer adjustment.

Suggested change
return const_cast<direct_control_block*>(this);
return static_cast<const protocol_view_cb_{{ c.name }}*>(this);

Copilot uses AI. Check for mistakes.
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.

2 participants