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

Missing lifetime specifier on functions returning concrete templates #1370

Open
BabaBert opened this issue Apr 9, 2024 · 2 comments
Open

Comments

@BabaBert
Copy link

BabaBert commented Apr 9, 2024

This might be an edge case but when a function returnr a reference to an innner templated member of an outer class or struct like this:

template <typename T> class B{
public:
    T& data;
};
class C{};
class A{
    public:
        B<C> data;
    };
B<C>& getInner(A& outer){
    return outer.data;
}

with macro usage like this:

generate!("A")
generate!("B")
generate!("C")
concrete!("B<C>", B_C)
generate!("getInner")

the autocxx generated rust code will have missing lifetime specifiers:

�[0m�[31m  |fn getInner (outer : Pin < & mut A >) -> Pin < & mut B_C > ;
�[0m�[31m  |                                                ^ expected named lifetime parameter
�[0m�[31m  |
�[0m�[31m  = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
�[0m�[31mhelp: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
BabaBert added a commit to BabaBert/autocxx that referenced this issue Apr 9, 2024
@BabaBert BabaBert changed the title Missing lifetime specifier on concrete templates Missing lifetime specifier on functions returning concrete templates Apr 9, 2024
@BabaBert
Copy link
Author

So the issue seems to be that the compiler can't derive the lifetime in this case. CXX generates the implementation differently for concrete types, and therefore Rusts elision rules aren't applicable.

@adetaylor
Copy link
Collaborator

Thanks for this - would you raise a PR for your tests?

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