Skip to content

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

Description

@consolexinhun

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugregressionRegression in a recent release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions