Skip to content

Possibly failing to detect template parameter T #1496

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
Belval opened this issue Jan 21, 2019 · 1 comment
Open

Possibly failing to detect template parameter T #1496

Belval opened this issue Jan 21, 2019 · 1 comment

Comments

@Belval
Copy link

Belval commented Jan 21, 2019

Input C/C++ Header

Header file itself can be found here. It's C++ 17 and uses templating.

namespace seal
{
    template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
    class IntArray
    {
    public:
        using size_type = std::size_t;

The definition seems pretty exotic so I suppose that something in it is unsupported.

Bindgen Invocation

 // Generate the bindings
    let bindings = bindgen::Builder::default()
        .generate_inline_functions(true)
        .derive_default(true)
        .header("./seal/src/seal/seal.h")
        .clang_arg("-I./seal/src/")
        .clang_arg("-std=c++17")
        .clang_arg("-x")
        .clang_arg("c++")
        .opaque_type("std::.*")
        .whitelist_type("seal::.*")
        .whitelist_function("seal::.*")
        .generate()
        .expect("Unable to generate bindings");

Actual Results

The bindings.rs file has an undefined T value in IntArray:

#[repr(C)]
#[derive(Debug)]
pub struct seal_IntArray {
    pub pool_: seal_MemoryPoolHandle,
    pub capacity_: seal_IntArray_size_type,
    pub size_: seal_IntArray_size_type,
    pub data_: seal_util_Pointer<T>,
}

Which causes the expected compilation error:

error[E0412]: cannot find type `T` in this scope
    --> src/./bindings.rs:6218:34
     |
6218 |     pub data_: seal_util_Pointer<T>,
     |                                  ^ not found in this scope

For reference, here is the relevant header file.

Expected Results

I would expect the generated code to compile.

For now, I have found that simply replacing T by u64 (since it's the only type they used as T in their code) works, but ideally I wouldn't have to edit the bindings by hand.

Possibly related: #1464
Also see issue: #1490

@boydjohnson
Copy link

Not OP, but I thought to run this through creduce.

I dumped preprocessor output for just src/seal/intarray.h which is not in master but is in the prior commit referenced above.

Running creduce with a predicate that runs bindgen master with --bindgen-args "--opaque-type std::.* --whitelist-type seal::.* --whitelist-function seal::.* -- -std=c++17 -x c++" produced this reduced header:

template <bool> struct a;
template <bool b> using c = typename a<b>::d;
namespace seal {
template <typename e, typename = c<e ::f>> class g { e h; };
template <typename e> class IntArray { g<e> h; };
} // namespace seal

bindgen --whitelist-type seal::.* bindgen.ii -- -x c++ -std=c++17

produces

cat bindings.rs 
/* automatically generated by rust-bindgen 0.58.1 */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct seal_g<e> {
    pub h: e,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<e>>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct seal_IntArray {
    pub h: seal_g<e>,
}

rustc --crate-type lib --test bindings.rs produces

error[E0412]: cannot find type `e` in this scope
  --> bindings.rs:12:19
   |
11 | pub struct seal_IntArray {
   |                         - help: you might be missing a type parameter: `<e>`
12 |     pub h: seal_g<e>,
   |                   ^ not found in this scope

error[E0412]: cannot find type `e` in this scope
  --> bindings.rs:12:19
   |
12 |     pub h: seal_g<e>,
   |                   ^ not found in this scope

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

3 participants