Repository navigation
core: diagnose overrider and virtual_ptr mistakes where they are made - #132
Merged
Merged
Conversation
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
|
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(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_assertthat names the problem, and that message is the first error on gcc, clang and MSVC.const:virtual_ptr<const Node>→virtual_ptr<Plus>,virtual_<const Node&>→Plus&dynamic_cast ... casts away qualifiersinstd_rtti.hppoverrider parameter discards const qualifierno viable conversion from returned valuein the thunkoverrider return type is not convertible to method return typevirtual_ptrin the method,shared_virtual_ptrin the overriderno viable conversion from 'virtual_ptr<Plus>' to 'virtual_ptr<std::shared_ptr<Plus>>'in the thunkdifferent virtual_ptr<> pointer kindsvirtual_ptr<Node>&initializethen aborted withunknown class virtual_ptr<Node, ...>virtual_ptr<> must be passed by value or by const referencevirtual_ptr<Node>&&method has no virtual parameters, or an ambiguousvalidate_overrider_parameterinstantiationvirtual_ptr<Node*>no matching functionvirtual_ptr<> takes a class or a smart pointer: virtual_ptr<Node>, not virtual_ptr<Node*>BOOST_OPENMETHOD_CLASSES<type_traits>andtypeiduse_classes: a class is incompleteNotes:
constcheck is limited to classes of one hierarchy. Interop parameters such asvirtual_<const std::any&>keep their own constraint and their existing diagnostics.virtual_ptr&andvirtual_ptr&&breaks nothing that worked. Both shapes were checked as non-virtual parameters too.&compiled but was dispatched as ifvirtual_ptrwere the class of the object.&&did not compile once an overrider existed.cannot find '...' method. That covers aconstoverrider for a non-constmethod, and a smartvirtual_ptrin 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 withvirtual_<> parameter is not a polymorphic class, before and after this change.std_shared_ptr.hpphas ashared_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_*.cppper check, eight in all, each with itsexpected-errormarker. Each was confirmed to compile once the mistake is fixed. Local runs:BOOST_OPENMETHOD_ENABLE_REFLECTION=ON: 207/207.toolset=gcc: exit 0, no warnings./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