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

[BUG]: void value not ignored as it ought to be #4117

Closed
2 of 3 tasks
consolexinhun opened this issue Aug 4, 2022 · 3 comments · Fixed by #4275
Closed
2 of 3 tasks

[BUG]: void value not ignored as it ought to be #4117

consolexinhun opened this issue Aug 4, 2022 · 3 comments · Fixed by #4275
Labels
bug regression Regression in a recent release

Comments

@consolexinhun
Copy link

consolexinhun commented Aug 4, 2022

Required prerequisites

Problem description

the bind code like this :

#include <pybind11/pybind11.h>
#include <iostream>
namespace py = pybind11;
using std::cout;
using std::endl;
class Animal {
public:
    virtual ~Animal() { }
    virtual void* go() = 0;
};

class PyAnimal : public Animal {
public:
    /* Inherit the constructors */
    using Animal::Animal;
    /* Trampoline (need one for each virtual function) */
    void* go() override {
        PYBIND11_OVERRIDE_PURE(
            void*, /* Return type */
            Animal,      /* Parent class */
            go,          /* Name of function in C++ (must match Python name) */
        );
    }
};

PYBIND11_MODULE(example, m) {
    py::class_<Animal, PyAnimal /* <--- trampoline*/>(m, "Animal")
        .def(py::init<>())
        .def("go", &Animal::go);
}

use pybind11 2.10.0,get error below:

example.cpp: In member function ‘virtual void* PyAnimal::go(int)’:
example.cpp:21:9: error: void value not ignored as it ought to be
   21 |         PYBIND11_OVERRIDE_PURE(
      |         ^~~~~~~~~~~~~~~~~~~~~~
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

but use pybind 2.9.2 is ok ,how to deal with it ??

Reproducible example code

No response

@henryiii
Copy link
Collaborator

I get

tmp.cpp:18:9: error: cannot initialize return object of type 'void *' with an rvalue of type 'enable_if_t<std::is_same<void, intrinsic_t<void *>>::value, void>' (aka 'void')
        PYBIND11_OVERRIDE_PURE(
        ^~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2826:5: note: expanded from macro 'PYBIND11_OVERRIDE_PURE'
    PYBIND11_OVERRIDE_PURE_NAME(                                                                  \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2788:9: note: expanded from macro 'PYBIND11_OVERRIDE_PURE_NAME'
        PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2754:20: note: expanded from macro 'PYBIND11_OVERRIDE_IMPL'
            return pybind11::detail::cast_safe<ret_type>(std::move(o));                           \
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

@henryiii
Copy link
Collaborator

Using #4272 and git bisect, the bad commit was 088ad4f, in #3861, by @laramiel.

@henryiii
Copy link
Collaborator

henryiii commented Oct 22, 2022

Debug mechanism:

$ gh pr checkout 279
$ cmd_to_run=c++ $(python3 -m pybind11 --file=example.cpp)
$ git bisect start
$ git bisect good v2.9.2
$ git bisect bad v2.10.0
$ git bisect run $cmd_to_run
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
Bisecting: 60 revisions left to test after this (roughly 6 steps)
[03252067db057777db75c2e5bcf0e69013b919ec] chore(deps): bump actions/upload-artifact from 2 to 3 (#3899)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
example.cpp:18:9: error: cannot initialize return object of type 'void *' with an rvalue of type 'enable_if_t<std::is_same<void, intrinsic_t<void *>>::value, void>' (aka 'void')
        PYBIND11_OVERRIDE_PURE(
        ^~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2808:5: note: expanded from macro 'PYBIND11_OVERRIDE_PURE'
    PYBIND11_OVERRIDE_PURE_NAME(                                                                  \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2770:9: note: expanded from macro 'PYBIND11_OVERRIDE_PURE_NAME'
        PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2736:20: note: expanded from macro 'PYBIND11_OVERRIDE_IMPL'
            return pybind11::detail::cast_safe<ret_type>(std::move(o));                           \
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Bisecting: 30 revisions left to test after this (roughly 5 steps)
[b22ee64c7309eb7344031b5e5385e6907d84c7eb] Add type_caster<std::monostate> (#3818)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
Bisecting: 15 revisions left to test after this (roughly 4 steps)
[9969f3b5b5ccad5524a9dab237b551c0ea6359f4] ci: drop win2016 (#3854)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
example.cpp:18:9: error: cannot initialize return object of type 'void *' with an rvalue of type 'enable_if_t<std::is_same<void, intrinsic_t<void *>>::value, void>' (aka 'void')
        PYBIND11_OVERRIDE_PURE(
        ^~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2808:5: note: expanded from macro 'PYBIND11_OVERRIDE_PURE'
    PYBIND11_OVERRIDE_PURE_NAME(                                                                  \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2770:9: note: expanded from macro 'PYBIND11_OVERRIDE_PURE_NAME'
        PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2736:20: note: expanded from macro 'PYBIND11_OVERRIDE_IMPL'
            return pybind11::detail::cast_safe<ret_type>(std::move(o));                           \
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Bisecting: 7 revisions left to test after this (roughly 3 steps)
[65ec5de52fecc974157a0c28490fef61204c39a1] chore: bump changelog for 2.9.2 (#3834)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[ab59f45d2ee05b1df299021b62ab1f59a768e285] Prefer make_caster<T> to type_caster<T> (#3859)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
Bisecting: 1 revision left to test after this (roughly 1 step)
[e3aa215b020886d648add951186052c619c3cf9d] Add perfect forwarding to make_iterator calls (#3860)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[088ad4f2987d3da4b1ffab376b2b4812fd7634ef] Cleanup cast_safe<void> specialization (#3861)
running  'clang++' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/usr/local/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10' '-I/Users/henryschreiner/git/software/pybind11/include' '-Wno-unused-result' '-Wsign-compare' '-Wunreachable-code' '-fno-common' '-dynamic' '-DNDEBUG' '-g' '-fwrapv' '-O3' '-Wall' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-std=c++11' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk' '-undefined' 'dynamic_lookup' 'example.cpp' '-o' 'example.cpython-310-darwin.so'
example.cpp:18:9: error: cannot initialize return object of type 'void *' with an rvalue of type 'enable_if_t<std::is_same<void, intrinsic_t<void *>>::value, void>' (aka 'void')
        PYBIND11_OVERRIDE_PURE(
        ^~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2808:5: note: expanded from macro 'PYBIND11_OVERRIDE_PURE'
    PYBIND11_OVERRIDE_PURE_NAME(                                                                  \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2770:9: note: expanded from macro 'PYBIND11_OVERRIDE_PURE_NAME'
        PYBIND11_OVERRIDE_IMPL(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__); \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/henryschreiner/git/software/pybind11/include/pybind11/pybind11.h:2736:20: note: expanded from macro 'PYBIND11_OVERRIDE_IMPL'
            return pybind11::detail::cast_safe<ret_type>(std::move(o));                           \
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct override_unused {};
1 error generated.
088ad4f2987d3da4b1ffab376b2b4812fd7634ef is the first bad commit
commit 088ad4f2987d3da4b1ffab376b2b4812fd7634ef
Author: Laramie Leavitt <laramiel@users.noreply.github.com>
Date:   Mon Apr 11 11:57:05 2022 -0700

    Cleanup cast_safe<void> specialization (#3861)

    * Cleanup cast_safe<void> specialization

    Replace explicit specialization of cast_safe<void> with SFINAE.
    It's better for SFINAE cases to cover all type-sets rather than mixing SFINAE and explicit specialization.

    Extracted from #3674

    * [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

    * Update cast.h

    Use detail::none_of<> as suggested
struct override_unused {};

  struct override_unused {};
    * [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

    * Update cast.h

    Reorder:
    If TEMP_REF
    If VOID
    if (!VOID && !TEMP_REF)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

 include/pybind11/cast.h | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
bisect found first bad commit⏎
  // Trampoline use: for reference/pointer types to value-converted values, we do a value cast, then

rwgk added a commit to rwgk/pybind11 that referenced this issue Oct 22, 2022
rwgk added a commit to rwgk/pybind11 that referenced this issue Oct 22, 2022
@Skylion007 Skylion007 added bug and removed triage New bug, unverified labels Oct 22, 2022
rwgk added a commit to rwgk/pybind11 that referenced this issue Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug regression Regression in a recent release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants