autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

Static function inside template classes are not generated properly

Open SDAChess opened this issue 5 months ago • 3 comments

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

SDAChess avatar Sep 19 '24 15:09 SDAChess