Constructing a protocol_view from a valueless protocol is undiagnosed, and calls through it hit a null function pointer

Abierto
#284 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@jbcoe ya está trabajando en esto.

Desde el 4/9/2026.

  • #305 de @jbcoe — cerrado sin fusionar

Evaluación

Este issue todavía no se ha evaluado.

Descripción

A moved-from protocol has object_ == nullptr and vtable_ == &null_vtable,
whose member entries are null function pointers. Calling a member function on
it directly is caught in debug builds: method_thunk::operator() asserts
!valueless_after_move() before dispatching.

Since #244 and #272 a protocol_view<I> or protocol_view<const I> constructs
implicitly from a protocol<I, A>&, copying object_ and vtable_. Nothing
checks the source, so a valueless protocol converts silently, and the thunk
assert is if constexpr (is_protocol_v<ProtocolType>), so it is compiled out
for views. A member call through such a view calls a null function pointer with
no diagnostic, even in a debug build.

protocol<Shape> a{Circle{}};
protocol<Shape> b = std::move(a);   // a is valueless
protocol_view<const Shape> v = a;   // accepted; comment says "Precondition: p is not valueless"
v.area();                           // release: null call; debug: also null call

The from-protocol constructors document the precondition in a comment
(protocol.hh, both protocol_view specializations) but do not enforce it.

Suggested fix, small enough for one PR:

  • assert(!p.valueless_after_move()) in the two from-protocol constructors.
  • Drop the is_protocol_v gate in method_thunk and assert object_ != nullptr
    instead, which covers protocol and view alike. A view's object_ is otherwise
    never null.
  • A death test for each path.

#208 settled the direct-call case as a precondition violation diagnosed by an
assert in debug builds; this extends the same contract to views. Raised in the
review of #272, where it was agreed to be out of scope there but worth fixing.

Lenguaje dominante
C++
Estrellas
12
Forks
4
Merge medio
1 d 11 h
PR fusionados (30 d)
15

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de jbcoe/cc-protocol

Todos los issues de jbcoe/cc-protocol

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.