Skip to content

Add test for nested template types #1479

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 1 commit into
base: main
Choose a base branch
from

Conversation

hallfox
Copy link

@hallfox hallfox commented Mar 30, 2025

It seems that generating a type with a member function that uses a reference to a typedef of a templated type causes autocxx to interpret the class with the typedef member as a namespace.

The extern "C++" generated the following from the submitted test case:

unsafe extern "C++" {
    #[cxx_name = "B"]
    type B = super::B;

    #[namespace = "B"]
    #[cxx_name = "F"]
    type B_F;
}

Which I believe is what causes the downstream issue that gets reported in the test failure:

cargo:warning=/tmp/.tmpTCdyDa/target/cxx/gen0.cxx:120:11: error: 'namespace B { }' redeclared as different kind of entity
cargo:warning=  120 | namespace B {
cargo:warning=      |           ^
cargo:warning=In file included from /tmp/.tmpTCdyDa/target/cxx/gen0.cxx:1:
cargo:warning=/tmp/.tmpTCdyDa/input.h:5:7: note: previous declaration 'class B'
cargo:warning=    5 | class B {
cargo:warning=      |       ^

I tried poking around RsCodeGenerator::generate_cxxbridge_type, which is where I think the actual generation of the buggy #[namespace = "B"] is coming from, but I don't really understand enough about how the namespace is being parsed to suggest a fix.

Maybe this is a known issue? There's some comments scattered around the source that seem to imply that some tricks are being done to handle nested types.

May be related to #1350

It seems that generating a type with a member function that uses
a reference to a typedef of a templated type causes autocxx to interpret
the typedef member as a namespace.

The `extern "C++"` generated the following from the submitted test case:

```rust
unsafe extern "C++" {
    #[cxx_name = "B"]
    type B = super::B;

    #[namespace = "B"]
    #[cxx_name = "F"]
    type B_F;
}
```

Which I believe is what causes the downstream issue that gets reported
in the test failure:

```
cargo:warning=/tmp/.tmpTCdyDa/target/cxx/gen0.cxx:120:11: error: 'namespace B { }' redeclared as different kind of entity
cargo:warning=  120 | namespace B {
cargo:warning=      |           ^
cargo:warning=In file included from /tmp/.tmpTCdyDa/target/cxx/gen0.cxx:1:
cargo:warning=/tmp/.tmpTCdyDa/input.h:5:7: note: previous declaration 'class B'
cargo:warning=    5 | class B {
cargo:warning=      |       ^
```

I tried poking around `RsCodeGenerator::generate_cxxbridge_type`, which
is where I think the actual generation of the buggy `#[namespace = "B"]`
is coming from, but I don't really understand enough about how the
namespace is being parsed to suggest a fix.

Maybe this is a known issue? There's some comments scattered around the
source that seem to imply that some tricks are being done to handle
nested types.
Copy link

google-cla bot commented Mar 30, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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