Enhance protocol templates for zero-indirection conversions#48
Enhance protocol templates for zero-indirection conversions#48
Conversation
There was a problem hiding this comment.
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{}; |
There was a problem hiding this comment.
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.
| 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{}; |
| }; | ||
|
|
||
| template <typename T> | ||
| inline constexpr protocol_view_const_dcb_{{ c.name }}<T> protocol_view_const_dcb_{{ c.name }}_inst{}; |
There was a problem hiding this comment.
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.
| 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{}; |
| } | ||
|
|
||
| const protocol_view_cb_{{ c.name }}* xyz_protocol_as_view_cb() const noexcept override { | ||
| return const_cast<direct_control_block*>(this); |
There was a problem hiding this comment.
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.
| return const_cast<direct_control_block*>(this); | |
| return static_cast<const protocol_view_cb_{{ c.name }}*>(this); |
No description provided.