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

Rename forward_like to avoid conflict with STL #475

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

yosh-matsuda
Copy link
Contributor

When nanobind user code enables C++23, I found that nanobind::detail::forward_like has a naming conflict with std::forward_like in STL due to ADL.

The situation is like this:

#include <utility>

namespace nanobind {
    template <typename T, typename U>
    auto forward_like(U&& t) { return t; }

    template <typename T>
    auto func(T&& t) { return forward_like<T>(t); }
}

int main() {
    auto p = std::pair(0, 0);
    nanobind::func(p);
    return 0;
}
x86-64 clang 17.0.1
x86-64 clang 17.0.1
-std=c++23 -stdlib=libc++ -Wall -Wextra 
123
<Compilation failed>

# For more information see the output window
x86-64 clang 17.0.1 - cached
<source>:8:31: error: call to 'forward_like' is ambiguous
    8 |     auto func(T&& t) { return forward_like<T>(t); }
      |                               ^~~~~~~~~~~~~~~

In particular, this will potentially occur when casting std object to a Python object using the nanobind STL caster.
The simplest solution is to rename forward_like (in this PR). We can also avoid ADL in other ways.

@wjakob
Copy link
Owner

wjakob commented Mar 13, 2024

Fair enough, thanks!

@wjakob wjakob merged commit afe2b83 into wjakob:master Mar 13, 2024
24 checks passed
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.

2 participants