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

Static function inside template classes are not generated properly #1393

Open
SDAChess opened this issue Sep 19, 2024 · 3 comments
Open

Static function inside template classes are not generated properly #1393

SDAChess opened this issue Sep 19, 2024 · 3 comments

Comments

@SDAChess
Copy link

Describe the bug
When declaring a static function inside a templated type, concrete type generation lack the static function, maybe I am doing something wrong here, is this normal behavior?

To Reproduce
src/test.h

#pragma once
#include <iostream>

template <typename T>
class Toto
{
public:
	static void test()
	{
		std::cout << "Test" << std::endl;
	}
};

src/main.rs

use autocxx::prelude::*;

include_cpp! {
    #include "test.h"
    safety!(unsafe_ffi)
    concrete!("Toto<int>", TotoInt)
}

fn main() {
    ffi::TotoInt::test();
}

build.rs

fn main() -> miette::Result<()> {
    let mut b = autocxx_build::Builder::new("src/main.rs", &["src"]).build()?;
    b.cpp(true).std("c++20").compile("autocxx-demo");
    println!("cargo:rerun-if-changed=src/main.rs");
    Ok(())
}

Cargo.toml

[package]
name = "test"
version = "0.1.0"
edition = "2021"

[dependencies]
cxx = "1.0"
autocxx = "0.27.0"

[build-dependencies]
autocxx-build = "0.27.0"
miette = { version = "5", features = ["fancy"] }

Expected behavior
Generate the corresponding call to the static function.

Additional context
Error message generated:

error[E0599]: no function or associated item named `test` found for struct `TotoInt` in the current scope
  --> src/main.rs:10:19
   |
10 |     ffi::TotoInt::test();
   |                   ^^^^ function or associated item not found in `TotoInt`
   |
  ::: /autocxx-ffi-default-gen.rs:1:1143
   |
1  | ...& str) -> UniquePtr < CxxString > ; type TotoInt ; include ! ("test.h") ; include ! ("autocxxgen_ffi.h") ; } extern "Rust" { } } # [allow (unused...
   |                                        ------------ function or associated item `test` not found for this struct
@adetaylor
Copy link
Collaborator

Thanks for the report. If you'd like me to look at this any time soon, please raise a pull request with a failing test in integration_tests.rs. I'm not actually sure whether I'd expect this to work, nor how hard it would be to get it to work.

@SDAChess
Copy link
Author

Will do, thanks a lot.

@SDAChess
Copy link
Author

Added a pull-request #1394

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