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
bdf6a5e8
Commit
bdf6a5e8
authored
Oct 23, 2019
by
Hans Dembinski
Committed by
Wenzel Jakob
Oct 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Report type names in return value policy-related cast exceptions (#1965)
parent
c27a6e13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
9 deletions
+26
-9
include/pybind11/cast.h
+23
-6
tests/test_copy_move.py
+3
-3
No files found.
include/pybind11/cast.h
View file @
bdf6a5e8
...
@@ -533,9 +533,17 @@ public:
...
@@ -533,9 +533,17 @@ public:
case
return_value_policy
:
:
copy
:
case
return_value_policy
:
:
copy
:
if
(
copy_constructor
)
if
(
copy_constructor
)
valueptr
=
copy_constructor
(
src
);
valueptr
=
copy_constructor
(
src
);
else
else
{
throw
cast_error
(
"return_value_policy = copy, but the "
#if defined(NDEBUG)
"object is non-copyable!"
);
throw
cast_error
(
"return_value_policy = copy, but type is "
"non-copyable! (compile in debug mode for details)"
);
#else
std
::
string
type_name
(
tinfo
->
cpptype
->
name
());
detail
::
clean_type_id
(
type_name
);
throw
cast_error
(
"return_value_policy = copy, but type "
+
type_name
+
" is non-copyable!"
);
#endif
}
wrapper
->
owned
=
true
;
wrapper
->
owned
=
true
;
break
;
break
;
...
@@ -544,9 +552,18 @@ public:
...
@@ -544,9 +552,18 @@ public:
valueptr
=
move_constructor
(
src
);
valueptr
=
move_constructor
(
src
);
else
if
(
copy_constructor
)
else
if
(
copy_constructor
)
valueptr
=
copy_constructor
(
src
);
valueptr
=
copy_constructor
(
src
);
else
else
{
throw
cast_error
(
"return_value_policy = move, but the "
#if defined(NDEBUG)
"object is neither movable nor copyable!"
);
throw
cast_error
(
"return_value_policy = move, but type is neither "
"movable nor copyable! "
"(compile in debug mode for details)"
);
#else
std
::
string
type_name
(
tinfo
->
cpptype
->
name
());
detail
::
clean_type_id
(
type_name
);
throw
cast_error
(
"return_value_policy = move, but type "
+
type_name
+
" is neither movable nor copyable!"
);
#endif
}
wrapper
->
owned
=
true
;
wrapper
->
owned
=
true
;
break
;
break
;
...
...
tests/test_copy_move.py
View file @
bdf6a5e8
...
@@ -5,13 +5,13 @@ from pybind11_tests import copy_move_policies as m
...
@@ -5,13 +5,13 @@ from pybind11_tests import copy_move_policies as m
def
test_lacking_copy_ctor
():
def
test_lacking_copy_ctor
():
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
m
.
lacking_copy_ctor
.
get_one
()
m
.
lacking_copy_ctor
.
get_one
()
assert
"
the object
is non-copyable!"
in
str
(
excinfo
.
value
)
assert
"is non-copyable!"
in
str
(
excinfo
.
value
)
def
test_lacking_move_ctor
():
def
test_lacking_move_ctor
():
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
m
.
lacking_move_ctor
.
get_one
()
m
.
lacking_move_ctor
.
get_one
()
assert
"
the object
is neither movable nor copyable!"
in
str
(
excinfo
.
value
)
assert
"is neither movable nor copyable!"
in
str
(
excinfo
.
value
)
def
test_move_and_copy_casts
():
def
test_move_and_copy_casts
():
...
@@ -98,7 +98,7 @@ def test_private_op_new():
...
@@ -98,7 +98,7 @@ def test_private_op_new():
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
m
.
private_op_new_value
()
m
.
private_op_new_value
()
assert
"
the object
is neither movable nor copyable"
in
str
(
excinfo
.
value
)
assert
"is neither movable nor copyable"
in
str
(
excinfo
.
value
)
assert
m
.
private_op_new_reference
()
.
value
==
1
assert
m
.
private_op_new_reference
()
.
value
==
1
...
...
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