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

nb::handle: make bool conversion explicit to avoid ambiguity with integer conversions in derived types #173

Merged
merged 1 commit into from
Apr 5, 2023

Commits on Apr 5, 2023

  1. nb::handle: make bool conversion explicit to avoid ambiguity with int…

    …eger conversions in derived types
    
    An `explicit operator bool()` can still be used in conditional tests without a cast (`if (h) { ... }`) and is a better match for the explicitness of, for example, `operator int()` in `nb::int_`. Without this change, if you write
    ```
    void fn(nb::int_ ival) {
        int i = ival;
        printf("%d\n", i);
    }
    ```
    then `fn(nb::int_(42))` will print 1. (Only implicit conversions are allowed by the initialization style used, so the implicit `operator bool` in `nb::handle` is eligible while the explicit `operator int` in `nb::int_` is not.)
    oremanj committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    74d0a8f View commit details
    Browse the repository at this point in the history