Skip to content

Commit

Permalink
handle noexcept in constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Nov 21, 2024
1 parent 8c13722 commit 7d35ea8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/litgen/tests/internal/adapted_types/adapted_class_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,31 @@ def test_instantiated_template() -> None:
# class Foo:
# values: ImVector_int
# def __init__(self, values: Optional[ImVector[int]] = None) -> None:


def test_noexcept():
code = """
struct GlTexture
{
GlTexture();
GlTexture(GlTexture&& other) noexcept = default;
GlTexture(Foo&& f) noexcept(false);
};
"""
options = litgen.LitgenOptions()
generated_code = litgen.generate_code(options, code)
# print("\n" + generated_code.pydef_code)
code_utils.assert_are_codes_equal(
generated_code.pydef_code,
"""
auto pyClassGlTexture =
py::class_<GlTexture>
(m, "GlTexture", "")
.def(py::init<>())
.def(py::init<GlTexture &&>(),
py::arg("other"))
.def(py::init<Foo &&>(),
py::arg("f"))
;
"""
)
7 changes: 7 additions & 0 deletions src/srcmlcpp/internal/cpp_types_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ def fill_constructor_decl(
constructor_decl.cpp_element_comments.comment_end_of_line += " " + child_text
elif child_tag == "attribute":
pass # compiler options, such as [[gnu::optimize(0)]]
elif child_tag == "noexcept":
arg_list = child.wrapped_child_with_tag("argument_list")
if arg_list is None:
constructor_decl._noexcept = ""
else:
constructor_decl._noexcept = arg_list.str_code_verbatim()
print(f"noexcept: {constructor_decl._noexcept}")
elif child_tag in ["block", "member_init_list"]:
pass # will be handled by parse_constructor
else:
Expand Down

0 comments on commit 7d35ea8

Please sign in to comment.