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
6277910a
Commit
6277910a
authored
Jan 11, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved error messaging: Cannot disown nullptr (as_unique_ptr).
parent
4a879cfd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
include/pybind11/smart_holder_poc.h
+4
-0
tests/core/smart_holder_poc_test.cpp
+7
-0
No files found.
include/pybind11/smart_holder_poc.h
View file @
6277910a
...
@@ -134,6 +134,10 @@ struct smart_holder {
...
@@ -134,6 +134,10 @@ struct smart_holder {
}
}
void
ensure_use_count_1
(
const
char
*
context
)
const
{
void
ensure_use_count_1
(
const
char
*
context
)
const
{
if
(
vptr
.
get
()
==
nullptr
)
{
throw
std
::
runtime_error
(
std
::
string
(
"Cannot disown nullptr ("
)
+
context
+
")."
);
}
if
(
vptr
.
use_count
()
!=
1
)
{
if
(
vptr
.
use_count
()
!=
1
)
{
throw
std
::
runtime_error
(
std
::
string
(
"Cannot disown use_count != 1 ("
)
+
throw
std
::
runtime_error
(
std
::
string
(
"Cannot disown use_count != 1 ("
)
+
context
+
")."
);
context
+
")."
);
...
...
tests/core/smart_holder_poc_test.cpp
View file @
6277910a
...
@@ -317,3 +317,10 @@ TEST_CASE("error_disowned_holder", "[E]") {
...
@@ -317,3 +317,10 @@ TEST_CASE("error_disowned_holder", "[E]") {
hld
.
as_unique_ptr
<
int
>
();
hld
.
as_unique_ptr
<
int
>
();
REQUIRE_THROWS_WITH
(
hld
.
lvalue_ref
<
int
>
(),
"Disowned holder (lvalue_ref)."
);
REQUIRE_THROWS_WITH
(
hld
.
lvalue_ref
<
int
>
(),
"Disowned holder (lvalue_ref)."
);
}
}
TEST_CASE
(
"error_cannot_disown_nullptr"
,
"[E]"
)
{
auto
hld
=
smart_holder
::
from_raw_ptr_take_ownership
(
new
int
(
19
));
hld
.
as_unique_ptr
<
int
>
();
REQUIRE_THROWS_WITH
(
hld
.
as_unique_ptr
<
int
>
(),
"Cannot disown nullptr (as_unique_ptr)."
);
}
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