Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
7c2461ee
Commit
7c2461ee
authored
Nov 20, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolve issue involving inheritance + def_static + override (fixes #511)
parent
405f6d1d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletions
+33
-1
include/pybind11/pybind11.h
+1
-1
tests/test_issues.cpp
+20
-0
tests/test_issues.py
+12
-0
No files found.
include/pybind11/pybind11.h
View file @
7c2461ee
...
...
@@ -260,7 +260,7 @@ protected:
chain
=
(
detail
::
function_record
*
)
rec_capsule
;
/* Never append a method to an overload chain of a parent class;
instead, hide the parent's overloads in this case */
if
(
chain
->
class_
!=
rec
->
class_
)
if
(
chain
->
scope
!=
rec
->
scope
)
chain
=
nullptr
;
}
// Don't trigger for things like the default __init__, which are wrapper_descriptors that we are intentionally replacing
...
...
tests/test_issues.cpp
View file @
7c2461ee
...
...
@@ -351,6 +351,26 @@ void init_issues(py::module &m) {
/// Issue #484: number conversion generates unhandled exceptions
m2
.
def
(
"test_complex"
,
[](
float
x
)
{
py
::
print
(
"{}"
_s
.
format
(
x
));
});
m2
.
def
(
"test_complex"
,
[](
std
::
complex
<
float
>
x
)
{
py
::
print
(
"({}, {})"
_s
.
format
(
x
.
real
(),
x
.
imag
()));
});
/// Issue #511: problem with inheritance + overwritten def_static
struct
MyBase
{
static
std
::
unique_ptr
<
MyBase
>
make
()
{
return
std
::
unique_ptr
<
MyBase
>
(
new
MyBase
());
}
};
struct
MyDerived
:
MyBase
{
static
std
::
unique_ptr
<
MyDerived
>
make
()
{
return
std
::
unique_ptr
<
MyDerived
>
(
new
MyDerived
());
}
};
py
::
class_
<
MyBase
>
(
m2
,
"MyBase"
)
.
def_static
(
"make"
,
&
MyBase
::
make
);
py
::
class_
<
MyDerived
,
MyBase
>
(
m2
,
"MyDerived"
)
.
def_static
(
"make"
,
&
MyDerived
::
make
)
.
def_static
(
"make2"
,
&
MyDerived
::
make
);
}
// MSVC workaround: trying to use a lambda here crashes MSCV
...
...
tests/test_issues.py
View file @
7c2461ee
...
...
@@ -237,3 +237,15 @@ def test_complex_cast(capture):
1.0
(0.0, 2.0)
"""
def
test_inheritance_override_def_static
():
from
pybind11_tests.issues
import
MyBase
,
MyDerived
b
=
MyBase
.
make
()
d1
=
MyDerived
.
make2
()
d2
=
MyDerived
.
make
()
assert
isinstance
(
b
,
MyBase
)
assert
isinstance
(
d1
,
MyDerived
)
assert
isinstance
(
d2
,
MyDerived
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment