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

Unable to Call Base Class Functions When Base is a Template Class in autocxx #1356

Open
edsky opened this issue Jan 18, 2024 · 1 comment
Open

Comments

@edsky
Copy link

edsky commented Jan 18, 2024

Describe the bug
There seems to be a limitation in autocxx when dealing with base classes that are templated. In the provided example, the base class S is a template, and the derived class B1 is unable to call any function from the templated base class or use its type deduction features.

To Reproduce
To reproduce the behavior, the following setup was used with Rust and C++ code snippets:

C++ Header (input.h):

#pragma once

#include <memory>

template <typename T>
class S {
    virtual void foo1() const {};
};

class A {
public:
    virtual void foo() const {};
    virtual ~A() {}
};

class B0 : public A {
public:
    void bar() const {}
};

class B1 : public S<A> {
public:
    void bar() const {}
};

Rust Code (main.rs):

autocxx::include_cpp!{
    #include "input.h"
    safety!(unsafe_ffi)
    generate!("S")
    generate!("A")
    generate!("B0")
    generate!("B1")
}

fn main() {
    use ffi::*;
    use autocxx::WithinUniquePtr;

    let b0 = B0::new().within_unique_ptr();
    b0.as_ref().unwrap().as_ref().foo();

    // let b1 = B1::new().within_unique_ptr();
    // b1.as_ref().unwrap().as_ref().foo1();
}

Expected behavior
The expected behavior is that autocxx should be able to handle template base classes and allow derived classes to call functions from these base classes. In the provided example, we expect B1 to be able to call foo1() from its base class S.

Additional context
Currently, autocxx seems to struggle with template inheritance, leading to difficulties in utilizing base class methods in derived classes. This issue appears to be specific to the handling of template classes in autocxx.

@adamnemecek
Copy link

Did you ever figure out a workaround? It seems like if you implement all the methods and forward it to the super class it works which is really annyoing.

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

No branches or pull requests

2 participants