Skip to content

Allow subclass!() of superclasses with protected destructors #1481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tchebb
Copy link
Contributor

@tchebb tchebb commented Apr 8, 2025

See individual commit messages for details. There were two blockers here:

  • The as_<superclass>_unique_ptr functions failed to compile on the C++ side because unique_ptr needs to point to a destructible type. I fixed that by just omitting those functions when the superclass is not destructible.
  • The synthesized subclass constructor, and in turn the automatic CppPeerConstructor implementation, were erroneously omitted for protected superclass destructors rather than only for private ones.

I'm not sure if my approach here, especially on commits 2 and 3, is ideal. I added a new analysis field for Api::Subclass, which resulted in a ton of new boilerplate. The new code's clean, but there's a lot of it. If you can think of a way to plumb the information through in a less invasive way, I'd be happy to do that instead.

tchebb added 4 commits April 8, 2025 00:29
Currently, we only synthesize a default constructor when the superclass
destructor is public. This is to comply with 11.4.5.2 of the C++
standard[1], which states that a default constructor is deleted if "any
potentially constructed subobject [e.g. the virtual base class] has a
type with a destructor that is deleted or inaccessible from the
defaulted default constructor".

We correctly exclude private base class destructors, which are not
accessible from the subclass's constructor. But we also exclude
protected base class destructors, which are! Fix that by matching
protected superclass destructors too.

[1] https://github.com/cplusplus/draft/releases/tag/n4917
It's exactly like what we already have for Enum, Typedef, Function, and
Struct. This commit just makes the boring structural changes: the field
itself is still empty. A future commit will use it to track superclass
destructor visibility.
Currently, we emit as_<superclass>_unique_ptr helpers for all Rust
subclasses. But this breaks subclasses derived from classes with private
or protected destructors, since unique_ptr needs to be able to destruct
the object it references. Fix that by omitting those helpers when we
know the superclass destructor is inaccessible.

The core changes are in codegen_rs and codegen_cpp; everything else is
just plumbing to get information about superclass destructor visibility
where it needs to be.
@tchebb tchebb changed the title Allow subclass!() for superclasses with protected destructors Allow subclass!() for superclasses with protected destructors Apr 8, 2025
@tchebb tchebb changed the title Allow subclass!() for superclasses with protected destructors Allow subclass!() of superclasses with protected destructors Apr 8, 2025
tchebb added a commit to tchebb/openwv that referenced this pull request Apr 16, 2025
This includes [1] and [2], which are both needed to generate bindings
from content_decryption_module.h without errors. If and when upstream
takes the fixes, we can pull from crates.io again.

[1] google/autocxx#1478
[2] google/autocxx#1481
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.

1 participant