Skip to content

Commit

Permalink
Mark libcpp.optional.value as except + (#6190)
Browse files Browse the repository at this point in the history
std::optional::value() raises a std::bad_optional_access
if it does not contain a value.
  • Loading branch information
arcondello committed May 9, 2024
1 parent 45db483 commit dbb4e6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cython/Includes/libcpp/optional.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cdef extern from "<optional>" namespace "std" nogil:
optional(optional&) except +
optional(T&) except +
bool has_value()
T& value()
T& value() except +
T& value_or[U](U& default_value)
void swap(optional&)
void reset()
Expand Down
6 changes: 6 additions & 0 deletions tests/run/cpp_stl_optional.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def simple_test():
"""
cdef optional[int] o
assert(not o.has_value())
try:
o.value()
except Exception as err:
pass
else:
assert False, "value() did not raise a catchable error"
o = 5
assert(o.has_value())
assert(o.value()==5)
Expand Down

0 comments on commit dbb4e6a

Please sign in to comment.