[BUG]: Pure virtual method overriding using mixin class gives: Tried to call pure virtual function …

オープン
#5,405 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp, python
領域
api

調査の方向性

再現可能な例にある C++ の mixin、抽象クラス、trampoline のセットアップから始め、次に対応する Python の多重継承ケースを実行します。pure virtual call がどのようにディスパッチされるかを追跡します。mixin が提供する f() の実装が使われ、pure-virtual error が発生しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

triage
Required prerequisites
What version (or hash if on master) of pybind11 are you using?

2.13.5

Problem description

I cant override pure virtual functions using mixin classes. Pybind does not realize that the function in question does exist but is provided by the mixin class.

Reproducible example code
struct M {
    int f() { return 1; }
};

struct A {
    virtual int f() = 0;
};

// Imagine a trampoline class AT for A here

PYBIND11_MODULE(example, m) {
    pybind11::class_<M>(m, "Mixin")
        .def("f", &M::f);
    pybind11::class_<A, AT>(m, "Abstract")
        .def("f", &A::f);
}
class Derived(M, A):
    ...

d = D()
d.foo()

The last statement throws "Tried to call pure virtual function". For example in plain Python this works as expected:

class A():
    def f(self):
        pass

class M:
    def f(self):
        return "mixed in"

class D(M, A):
     pass

d = D()
print(d.f())
Is this a regression? Put the last known working version here if it is.

Not a regression

主要言語
C++
スター
18k
フォーク
2.3k
平均マージ
5日 7時間
マージ済み PR(30日)
53

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pybind/pybind11 のほかの issue

pybind/pybind11 の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。