Skip to content

C++: --enable-cxx-namespaces can fail to generate type aliases #1435

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

Closed
sanxiyn opened this issue Nov 7, 2018 · 4 comments
Closed

C++: --enable-cxx-namespaces can fail to generate type aliases #1435

sanxiyn opened this issue Nov 7, 2018 · 4 comments

Comments

@sanxiyn
Copy link
Member

sanxiyn commented Nov 7, 2018

Input C/C++ Header

namespace ns {
enum class AB { A, B };
}
using AB = ns::AB;
static const AB kA = AB::A;

Bindgen Invocation

$ bindgen input.h --enable-cxx-namespaces -- -x c++

Actual Results

/* automatically generated by rust-bindgen */

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    pub mod ns {
        #[allow(unused_imports)]
        use self::super::super::root;
        pub const AB_A: root::ns::AB = 0;
        pub const AB_B: root::ns::AB = 1;
        pub type AB = i32;
    }
    extern "C" {
        #[link_name = "\u{1}kA"]
        pub static kA: root::AB;
    }
}

Expected Results

The output does not compile. It seems to me something like pub use root::ns::AB as AB; is missing.

@sanxiyn
Copy link
Member Author

sanxiyn commented Nov 7, 2018

Investigation

There is no problem if --enable-cxx-namespaces is not used.

There is no problem if using ABC = ns::AB; is used instead.

@sanxiyn
Copy link
Member Author

sanxiyn commented Nov 7, 2018

Looking at codegen for TypeKind::Alias in src/codegen/mod.rs, it seems to me code to handle #946 should compare canonical path, not canonical name, but I am not familiar enough with bindgen codebase to be sure.

@emilio
Copy link
Contributor

emilio commented Nov 7, 2018

Yes, that sounds right, nice catch!

Wanna submit a patch? :)

@sanxiyn
Copy link
Member Author

sanxiyn commented Nov 7, 2018

Wow, thanks for a super fast reply!

Given my analysis is correct, I should be able to come up with a patch. Please wait a minute. :)

bors-servo pushed a commit that referenced this issue Nov 8, 2018
Use canonical path for type alias loop detection

Fix #1435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants