Skip to content
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

Panic with C++ template templates #555

Closed
gsingh93 opened this issue Mar 4, 2017 · 4 comments
Closed

Panic with C++ template templates #555

gsingh93 opened this issue Mar 4, 2017 · 4 comments
Labels

Comments

@gsingh93
Copy link

gsingh93 commented Mar 4, 2017

Input C/C++ Header

template <template <typename> class Bar>
struct Foo {
private:
    static Bar<unsigned> bar;
};

Bindgen Invokation

$ bindgen test.h -- -x c++ -std=c++14
thread 'main' panicked at 'assertion failed: `(left == right)` (left: `1`, right: `118`): Couldn't resolve constant type, and it wasn't an nondeductible auto type!', /Users/gulshan/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.22.0/src/ir/var.rs:190
stack backtrace:
   1:        0x101d2ba8a - std::sys::imp::backtrace::tracing::imp::write::hd3b65cdfe843284c
   2:        0x101d2f08f - std::panicking::default_hook::{{closure}}::hf2b7428652613d83
   3:        0x101d2ed37 - std::panicking::default_hook::h5da8f27db5582938
   4:        0x101d2f556 - std::panicking::rust_panic_with_hook::hcef1e67c646c6802
   5:        0x101d2f3f4 - std::panicking::begin_panic::hc2e8ca89533cd10d
   6:        0x101d2f312 - std::panicking::begin_panic_fmt::h60990696c3c3a88d
   7:        0x101aa2943 - <bindgen::ir::var::Var as bindgen::parse::ClangSubItemParser>::parse::h731a1c48c5364448
   8:        0x101a97755 - <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::parse::ha854b5c1a690676f
   9:        0x101a7adb0 - bindgen::clang::visit_children::h407f548956a98527
  10:        0x10240351d - _ZN5clang8cxcursor13CursorVisitor5VisitE8CXCursorb
  11:        0x102404fa9 - _ZN5clang8cxcursor13CursorVisitor23handleDeclForVisitationEPKNS_4DeclE
  12:        0x102405052 - _ZN5clang8cxcursor13CursorVisitor16VisitDeclContextEPNS_11DeclContextE
  13:        0x102405b4f - _ZN5clang8cxcursor13CursorVisitor18VisitCXXRecordDeclEPNS_13CXXRecordDeclE
  14:        0x1024067b9 - _ZN5clang8cxcursor13CursorVisitor22VisitClassTemplateDeclEPNS_17ClassTemplateDeclE
  15:        0x102404be3 - _ZN5clang11declvisitor4BaseINS0_8make_ptrENS_8cxcursor13CursorVisitorEbE5VisitEPNS_4DeclE
  16:        0x102403d9f - _ZN5clang8cxcursor13CursorVisitor13VisitChildrenE8CXCursor
  17:        0x10240dfb9 - clang_visitChildren
  18:        0x101b3f473 - clang_sys::clang_visitChildren::h3c5e08c86622e596
  19:        0x101a85d61 - bindgen::ir::comp::CompInfo::from_ty::h8e4ee1f45389b0ff
  20:        0x101aa0b9e - bindgen::ir::ty::Type::from_clang_ty::hfb38fbdebe1efd4c
  21:        0x101a99938 - <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::from_ty_with_id::h8e24d164a9603af1
  22:        0x101a982f9 - <bindgen::ir::item::Item as bindgen::parse::ClangItemParser>::parse::ha854b5c1a690676f
  23:        0x101aa8309 - bindgen::parse_one::h35c930a99bf4fd69
  24:        0x101a7c492 - bindgen::clang::visit_children::h4fa0b4d826846788
  25:        0x10240351d - _ZN5clang8cxcursor13CursorVisitor5VisitE8CXCursorb
  26:        0x102404fa9 - _ZN5clang8cxcursor13CursorVisitor23handleDeclForVisitationEPKNS_4DeclE
  27:        0x102405052 - _ZN5clang8cxcursor13CursorVisitor16VisitDeclContextEPNS_11DeclContextE
  28:        0x102403eb2 - _ZN5clang8cxcursor13CursorVisitor13VisitChildrenE8CXCursor
  29:        0x10240dfb9 - clang_visitChildren
  30:        0x101b3f473 - clang_sys::clang_visitChildren::h3c5e08c86622e596
  31:        0x101aa4e22 - bindgen::Bindings::generate::h10a95595a3650a40
  32:        0x101aa448a - bindgen::Builder::generate::h182f654606cf3bb2
  33:        0x101a2c52b - std::panicking::try::do_call::hf25b075f9f1bf285
  34:        0x101d303ca - __rust_maybe_catch_panic
  35:        0x101a49515 - bindgen::main::hf1dbef6d6a3a6c4e
  36:        0x101d303ca - __rust_maybe_catch_panic
  37:        0x101d2f8f6 - std::rt::lang_start::h87cb84a8b6cb187e

Expected Results

This shouldn't panic.

RUST_LOG=bindgen Output

INFO:bindgen: Clang Version: clang version 3.9.0 (tags/RELEASE_390/final)
DEBUG:bindgen::ir::context: BindgenContext::add_item(Item { id: ItemId(0), local_id: Cell { value: None }, next_child_local_id: Cell { value: 1 }, canonical_name_cache: RefCell { value: None }, comment: None, annotations: Annotations { opaque: false, hide: false, use_instead_of: None, disallow_copy: false, private_fields: None, accessor_kind: None, constify_enum_variant: false }, parent_id: ItemId(0), kind: Module(Module { name: Some("root"), kind: Normal, children_ids: [] }) }, declaration: None, loc: None
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(1), ty: Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")), id: ItemId(1) }]
WARN:bindgen::ir::comp: Unknown kind for comp type: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)
DEBUG:bindgen::ir::comp: CompInfo::from_ty(Struct, Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")))
WARN:bindgen::ir::comp: unhandled comp member `Bar` (kind 29) in `Foo` (test.h:1:37)
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(Bar<unsigned int>, kind: Unexposed, decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), canon: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), Some(Cursor(bar kind: VarDecl, loc: test.h:4:26, usr: Some("c:@ST>1#t>1#T@Foo@bar"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(Bar<unsigned int>, kind: Unexposed, decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), canon: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), Some(Cursor(bar kind: VarDecl, loc: test.h:4:26, usr: Some("c:@ST>1#t>1#T@Foo@bar"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(2), ty: Type(Bar<unsigned int>, kind: Unexposed, decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), canon: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), loc: Some(Cursor(bar kind: VarDecl, loc: test.h:4:26, usr: Some("c:@ST>1#t>1#T@Foo@bar")))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")), id: ItemId(1) }, PartialType { decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), id: ItemId(2) }]
DEBUG:bindgen::ir::ty: Looking for canonical type: Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None)), Some(Cursor(bar kind: VarDecl, loc: test.h:4:26, usr: Some("c:@ST>1#t>1#T@Foo@bar"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(2), ty: Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None)), loc: Some(Cursor(bar kind: VarDecl, loc: test.h:4:26, usr: Some("c:@ST>1#t>1#T@Foo@bar")))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")), id: ItemId(1) }, PartialType { decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), id: ItemId(2) }]
WARN:bindgen::ir::ty: Unexposed type Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None)), recursing inside, loc: Cursor(bar kind: VarDecl, loc: test.h:4:26, usr: Some("c:@ST>1#t>1#T@Foo@bar"))
DEBUG:bindgen::ir::item: Item::from_ty recursing in the ast
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(Bar<unsigned int>, kind: Unexposed, decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), canon: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), Some(Cursor(Bar kind: TemplateRef, loc: test.h:4:12, usr: None)), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(Bar<unsigned int>, kind: Unexposed, decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), canon: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), Some(Cursor(Bar kind: TemplateRef, loc: test.h:4:12, usr: None)), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(2), ty: Type(Bar<unsigned int>, kind: Unexposed, decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), canon: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), loc: Some(Cursor(Bar kind: TemplateRef, loc: test.h:4:12, usr: None))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")), id: ItemId(1) }, PartialType { decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), id: ItemId(2) }]
DEBUG:bindgen::ir::ty: Looking for canonical type: Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None)), Some(Cursor(Bar kind: TemplateRef, loc: test.h:4:12, usr: None)), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(2), ty: Type(<unsigned int>, kind: Unexposed, decl: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None), canon: Cursor( kind: TemplateTemplateParameter, loc: builtin definitions, usr: None)), loc: Some(Cursor(Bar kind: TemplateRef, loc: test.h:4:12, usr: None))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")), id: ItemId(1) }, PartialType { decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), id: ItemId(2) }]
DEBUG:bindgen::ir::ty: TemplateRef: location = Cursor(Bar kind: TemplateRef, loc: test.h:4:12, usr: None); referenced = Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")); referenced_ty = Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None))
DEBUG:bindgen::ir::context: builtin_or_resolved_ty: Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), Some(Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10"))), None
DEBUG:bindgen::ir::context: Not resolved, maybe builtin?
DEBUG:bindgen::ir::ty: from_clang_ty: ItemId(2), ty: Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)), loc: Some(Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")))
DEBUG:bindgen::ir::ty: currently_parsed_types: [PartialType { decl: Cursor(Foo kind: ClassTemplate, loc: test.h:2:8, usr: Some("c:@ST>1#t>1#T@Foo")), id: ItemId(1) }, PartialType { decl: Cursor(Bar kind: TemplateTemplateParameter, loc: test.h:1:37, usr: Some("c:test.h@10")), id: ItemId(2) }]
WARN:bindgen::ir::ty: invalid type Type(, kind: Invalid, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None))
thread 'main' panicked at 'assertion failed: `(left == right)` (left: `1`, right: `118`): Couldn't resolve constant type, and it wasn't an nondeductible auto type!', /Users/gulshan/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.22.0/src/ir/var.rs:190
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@gsingh93 gsingh93 changed the title Panic with template argument that takes a template parameter Panic with C++ template templates Mar 4, 2017
@fitzgen
Copy link
Member

fitzgen commented Mar 4, 2017

Thanks for the bug report!

Rust doesn't have higher kinded types, so we can't meaningfully translate template template parameters to Rust right now. We should however not panic and generate opaque blobs in the place of instantiations of template definitions with template template parameters.

Note to self: need to revisit this once #544 lands.

@fitzgen fitzgen added the bug label Mar 4, 2017
@gsingh93
Copy link
Author

gsingh93 commented Mar 4, 2017

Yup, not panicing is all I'm looking for here, otherwise I'm just unable to generate my bindings for the types I've whitelisted (I got this code from an included library).

@emilio
Copy link
Contributor

emilio commented Mar 4, 2017

Yeah, this is mostly a duplicate of #388.

@gsingh93
Copy link
Author

gsingh93 commented Mar 5, 2017

You're right, this is an exact duplicate. @jsgf's code is actually the original code I ran into which was causing the panic :)

@gsingh93 gsingh93 closed this as completed Mar 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants