Skip to content

core: diagnose overrider and virtual_ptr mistakes where they are made - #132

Merged
jll63 merged 2 commits into
boostorg:developfrom
jll63:fix/diagnostics
Oct 18, 2026
Merged

jll63 merged 2 commits into
boostorg:developfrom
jll63:fix/diagnostics

Conversation

@jll63

@jll63 jll63 commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

(Written by Claude Code, on behalf of @jll63.)

Six mistakes used to fail deep inside the library: in the overrider thunk, the type traits, or at dispatch. The user's own declaration showed up only in an instantiation note, or not at all. Each now fails with a static_assert that names the problem, and that message is the first error on gcc, clang and MSVC.

Mistake Before Now
Overrider drops const: virtual_ptr<const Node> → virtual_ptr<Plus>, virtual_<const Node&> → Plus& dynamic_cast ... casts away qualifiers in std_rtti.hpp overrider parameter discards const qualifier
Overrider return type does not convert to the method's no viable conversion from returned value in the thunk overrider return type is not convertible to method return type
Plain virtual_ptr in the method, shared_virtual_ptr in the overrider no viable conversion from 'virtual_ptr<Plus>' to 'virtual_ptr<std::shared_ptr<Plus>>' in the thunk different virtual_ptr<> pointer kinds
Method takes virtual_ptr<Node>& compiled; initialize then aborted with unknown class virtual_ptr<Node, ...> virtual_ptr<> must be passed by value or by const reference
Method takes virtual_ptr<Node>&& method has no virtual parameters, or an ambiguous validate_overrider_parameter instantiation same as above
virtual_ptr<Node*> declaration accepted; every call then fails with no matching function virtual_ptr<> takes a class or a smart pointer: virtual_ptr<Node>, not virtual_ptr<Node*>
Incomplete class in BOOST_OPENMETHOD_CLASSES 5 errors inside <type_traits> and typeid use_classes: a class is incomplete

Notes:

  • The const check is limited to classes of one hierarchy. Interop parameters such as virtual_<const std::any&> keep their own constraint and their existing diagnostics.
  • Rejecting virtual_ptr& and virtual_ptr&& breaks nothing that worked. Both shapes were checked as non-virtual parameters too. & compiled but was dispatched as if virtual_ptr were the class of the object. && did not compile once an overrider existed.
  • The opposite of two mismatches is already reported, by cannot find '...' method. That covers a const overrider for a non-const method, and a smart virtual_ptr in the method with a plain one in the overrider. In both cases the overrider's arguments do not convert to the method's parameters, so the macro cannot find the method.

Found and left alone: virtual_<std::shared_ptr<Node>&&> fails with virtual_<> parameter is not a polymorphic class, before and after this change. std_shared_ptr.hpp has a shared_ptr_cast_traits<std::shared_ptr<T>&&> specialization, so the shape may be meant to work. That looks like a separate bug rather than a diagnostic problem.

Tests: one test/compile_fail_*.cpp per check, eight in all, each with its expected-error marker. Each was confirmed to compile once the mistake is fixed. Local runs:

  • clang 22 and gcc 16: 206/206.
  • g++-16 with BOOST_OPENMETHOD_ENABLE_REFLECTION=ON: 207/207.
  • b2 toolset=gcc: exit 0, no warnings.
  • MSVC v18 (/W4 /permissive-): every new test leads with its message, and positive examples compile cleanly.

The troubleshooting page that documents these messages is in a follow-up PR stacked on this branch.

🤖 Generated with Claude Code

https://claude.ai/code/session_016NKQZ2ktRZ1AjCgSLLeXma

jll63 and others added 2 commits October 18, 2026 10:37
A method taking `virtual_ptr<const Node>` or `virtual_<const Node&>` with
an overrider taking `virtual_ptr<Variable>` or `Variable&` used to fail
deep inside the thunk, on a `dynamic_cast` that casts away constness,
with the overrider named only in an instantiation note.
`validate_overrider_parameter` now checks constness next to the registry,
for every virtual_ptr shape and for references and pointers between
classes of one hierarchy. Interop parameters such as
`virtual_<const std::any&>` keep their own constraint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016NKQZ2ktRZ1AjCgSLLeXma
… library

Each of these used to fail in the library's internals - the thunk, the
type traits, the dispatch - with the user's declaration named only in an
instantiation note, or not at all:

- an overrider whose return type does not convert to the method's
  ("overrider return type is not convertible to method return type");
- a plain virtual_ptr in the method and a smart one in the overrider, or
  two different smart pointers ("different virtual_ptr<> pointer kinds");
- a method taking a virtual_ptr by non-const lvalue reference, which
  cannot bind to the virtual_ptr of a derived class and was dispatched as
  if virtual_ptr were the class of the object, or by rvalue reference,
  which is not a virtual parameter at all ("virtual_ptr<> must be passed
  by value or by const reference");
- virtual_ptr<Node*> ("virtual_ptr<> takes a class or a smart pointer");
- an incomplete class in use_classes ("use_classes: a class is
  incomplete").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016NKQZ2ktRZ1AjCgSLLeXma
@cppalliance-bot

Copy link
Copy Markdown

An automated preview of the documentation is available at https://132.openmethod.prtest3.cppalliance.org/libs/openmethod/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-10-18 15:16:20 UTC

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.34%. Comparing base (5356efb) to head (63dc301).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #132   +/-   ##
========================================
  Coverage    92.34%   92.34%           
========================================
  Files           27       27           
  Lines         2234     2234           
  Branches       677      677           
========================================
  Hits          2063     2063           
  Misses         112      112           
  Partials        59       59           
Files with missing lines Coverage Δ
include/boost/openmethod/core.hpp 91.80% <ø> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5356efb...63dc301. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jll63
jll63 merged commit 5a5e67b into boostorg:develop Oct 18, 2026
55 of 56 checks passed
@jll63
jll63 deleted the fix/diagnostics branch October 18, 2026 16:48
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