Skip to content

Fix late instantiated virtual methods - #411

Merged
nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:late-instantiated-methods
Sep 21, 2026
Merged

nunoplopes merged 6 commits into
Cpp2Rust:masterfrom
lucic71:late-instantiated-methods

Conversation

@lucic71

@lucic71 lucic71 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

#394 translates records that contain declared but not defined methods. That did not cover virtual methods in derived records. This PR solves that.

cpp2rust generated an empty impl Base for Derived {} when no virtual method had a definition. Then, when an out-of-line definition was encountered, cpp2rust refused it because multiple impl Base for Derived {} are not allowed by rustc. This resulted in usages of undefiend methods because neither the record visitor nor the out-of-line method visitor generated the methods.

The fix is to defer the impl Base for Derived {} block at the end of the file, similar to how methods on Ptr are deferred. At the end of the file, where every TU was visited, we know all the methods that have definitions.

@nunoplopes
nunoplopes merged commit 79a9acd into Cpp2Rust:master Sep 21, 2026
9 checks passed
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