Skip to content

Enable protocol_view to be constructed from protocol without extra indirection#56

Closed
jbcoe wants to merge 9 commits intomainfrom
jbcoe/view-from-protocol
Closed

Enable protocol_view to be constructed from protocol without extra indirection#56
jbcoe wants to merge 9 commits intomainfrom
jbcoe/view-from-protocol

Conversation

@jbcoe
Copy link
Copy Markdown
Owner

@jbcoe jbcoe commented Apr 3, 2026

No description provided.

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 4 comments.


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

Comment on lines +110 to +112
template <typename T>
inline constexpr protocol_view_dcb_{{ c.name }}<T> protocol_view_dcb_{{ c.name }}_inst{};

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

protocol_view_dcb_... is a polymorphic type (has virtual functions), so it is not a literal type. Declaring inline constexpr protocol_view_dcb_..._inst{} is ill-formed because constexpr variables require a literal type. Consider making this an inline const object, or (preferably) provide a static const ...& instance() that returns a function-local static to avoid global dynamic initialization costs/order issues.

Copilot uses AI. Check for mistakes.
Comment on lines +133 to +134
template <typename T>
inline constexpr protocol_view_const_dcb_{{ c.name }}<T> protocol_view_const_dcb_{{ c.name }}_inst{};
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

Same issue as above: protocol_view_const_dcb_... is polymorphic, so inline constexpr protocol_view_const_dcb_..._inst{} is ill-formed (non-literal type). Use a non-constexpr storage strategy (e.g., inline const or a function-local static accessor).

Copilot uses AI. Check for mistakes.
requires protocol_concept_{{ c.name }}<T> && (!std::same_as<std::remove_cvref_t<T>, protocol_view>)
constexpr protocol_view(T& obj) noexcept
requires protocol_const_concept_{{ c.name }}<T> &&
(!std::same_as<std::remove_cvref_t<T>, protocol_view>)
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The templated ctor in protocol_view<const ...> only excludes its own specialization (protocol_view<const ...>), so it still accepts protocol_view<...> as T. That allows creating a “view of a view” (extra indirection) and can also dangle in common patterns like protocol_view<const I> v = protocol_view<I>(obj); (binds to a temporary view instead of using the shallow conversion operator). Consider tightening the constraint to also exclude protocol_view<{{ full_class_name }}> (and ideally both view specializations) so conversions between views go through the dedicated shallow path.

Suggested change
(!std::same_as<std::remove_cvref_t<T>, protocol_view>)
(!std::same_as<std::remove_cvref_t<T>, protocol_view>) &&
(!std::same_as<std::remove_cvref_t<T>,
protocol_view<{{ full_class_name }}}>)

Copilot uses AI. Check for mistakes.
requires protocol_concept_{{ c.name }}<T> && (!std::same_as<std::remove_cvref_t<T>, protocol_view>)
constexpr protocol_view(T& obj) noexcept
requires protocol_const_concept_{{ c.name }}<T> &&
(!std::same_as<std::remove_cvref_t<T>, protocol_view>)
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

Same “view of a view” issue here: the protocol_view<const ...> templated ctor only excludes its own specialization, so protocol_view<...> can match and produce a const view that points at the view object (extra indirection, and potential dangling if the source view is a temporary). Tighten the requires to exclude the other protocol_view specialization(s) so the shallow conversion operator is the only viable path.

Suggested change
(!std::same_as<std::remove_cvref_t<T>, protocol_view>)
(!std::same_as<std::remove_cvref_t<T>, protocol_view>) &&
(!std::same_as<std::remove_cvref_t<T>,
protocol_view<{{ full_class_name }}>>)

Copilot uses AI. Check for mistakes.
@jbcoe jbcoe closed this Apr 3, 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.

2 participants