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

fix: add missing std::forward calls #3443

Merged
merged 6 commits into from
Nov 7, 2021
Merged

fix: add missing std::forward calls #3443

merged 6 commits into from
Nov 7, 2021

Conversation

Boris-Rasin
Copy link
Contributor

@Boris-Rasin Boris-Rasin commented Nov 5, 2021

Two of the four cpp_function overloads are missing std::forward calls, which seems like a simple oversight.

Description

Suggested changelog entry:

add missing std::forward calls to some ``cpp_function`` overloads

Two of the four cpp_function overloads are missing std::forward calls, which seems like a simple oversight.
Copy link
Collaborator

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an oversight from #2213 . Looks good to me. Ping @rwgk

@rwgk
Copy link
Collaborator

rwgk commented Nov 5, 2021

Hi @Boris-Rasin, thanks for fixing the oversight, looks good to me.
I'm guessing you noticed because something broke. Ideally we'd add corresponding new tests. Distilling tests from a known breakage is much easier than having to imagine them out of thin air. Is there a chance you could try distilling out unit tests? Alternatively, could you please post the error message(s) here?

@Boris-Rasin
Copy link
Contributor Author

Hi @rwgk, ref qualified methods with rvalue reference parameters were broken:

struct RValueParam {
    void func1(std::string&&) {}
    void func2(std::string&&) const {}
    void func3(std::string&&) & {}
    void func4(std::string&&) const & {}
};

void init(pybind11::module& m)
{
  pybind11::class_<RValueParam>(m, "RValueParam")
    .def("func1", &RValueParam::func1) //ok
    .def("func2", &RValueParam::func2) //ok
    .def("func3", &RValueParam::func3) //error
    .def("func4", &RValueParam::func4) //error
  ;
}

// error message:
// pybind11/pybind11.h(118,74): error C2664: 'Return (std::string &&) &': cannot convert argument 1 from 'std::string' to 'std::string &&'

@rwgk
Copy link
Collaborator

rwgk commented Nov 5, 2021

Hi @rwgk, ref qualified methods with rvalue reference parameters were broken:

Thanks! It'd be great if you could add that to this PR, similar to what you see here (really straightforward):

https://github.com/pybind/pybind11/pull/2213/files

@rwgk
Copy link
Collaborator

rwgk commented Nov 5, 2021

I triggered the CI, although I'm not sure if you're still working on tests/test_methods_and_attributes.py, to prove that the methods are actually runnable. Anything trivial is good enough for this PR, e.g (untested).

std::size_t func1(std::string&& s) { return s.size(); }
...
assert obj.func1('boo') == 3
...

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding the tests!
Holding off merging only to give @Skylion007 a chance to look at the tests, too.

@Skylion007 Skylion007 merged commit 01f938e into pybind:master Nov 7, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Nov 7, 2021
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Dec 21, 2021
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

Successfully merging this pull request may close these issues.

4 participants