8000 Add testcase with constexpr constructor and trampoline by virtuald · Pull Request #238 · robotpy/robotpy-build · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add testcase with constexpr constructor and trampoline #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion robotpy_build/autowrap/render_cls_rpy_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _render_cls_trampoline(
r.write_trim(
f"""
template <typename PyTrampolineBase{ precomma(template_parameter_list) }, typename PyTrampolineCfg>
struct PyTrampoline_{ cls.full_cpp_name_identifier } : PyTrampolineBase, virtual py::trampoline_self_life_support {{
struct PyTrampoline_{ cls.full_cpp_name_identifier } : PyTrampolineBase {{
using PyTrampolineBase::PyTrampolineBase;
"""
)
Expand Down
11 changes: 10 additions & 1 deletion robotpy_build/autowrap/render_pybind11.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,16 @@ def cls_consts(r: RenderBuffer, cls: ClassContext):
def cls_decl(r: RenderBuffer, cls: ClassContext):
if cls.trampoline:
tctx = cls.trampoline
r.writeln(f"using {tctx.var} = {tctx.full_cpp_name};")
# py::trampoline_self_life_support
r.write_trim(
f"""
struct {tctx.var} : {tctx.full_cpp_name}, py::trampoline_self_life_support {{
using RpyBase = {tctx.full_cpp_name};
using RpyBase::RpyBase;
}};

"""
)
r.writeln(
f'static_assert(std::is_abstract<{tctx.var}>::value == false, "{cls.full_cpp_name} " RPYBUILD_BAD_TRAMPOLINE);'
)
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp/rpytest/ft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ClassWithFields,
ClassWithIgnored,
ClassWithTrampoline,
ConstexprTrampoline,
DocAppendClass,
DocAppendEnum,
DocClass,
Expand Down Expand Up @@ -123,6 +124,7 @@
"ClassWithFields",
"ClassWithIgnored",
"ClassWithTrampoline",
"ConstexprTrampoline",
"DocAppendClass",
"DocAppendEnum",
"DocClass",
Expand Down
16 changes: 16 additions & 0 deletions tests/cpp/rpytest/ft/include/trampoline.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ struct ClassWithTrampoline {
// bug: ensure this doesn't get forwarded
ClassWithTrampoline(const int &name) {}
};


struct ConstexprTrampoline {
constexpr ConstexprTrampoline() = default;
constexpr virtual ~ConstexprTrampoline() = default;
constexpr virtual int fn() const = 0;
};

struct ChildConstexprTrampoline : ConstexprTrampoline {
constexpr ChildConstexprTrampoline(int i) : something(i) {}
constexpr int fn() const override {
return 1;
}

int something;
};
6 changes: 5 additions & 1 deletion tests/test_ft_trampoline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rpytest.ft import ClassWithTrampoline
from rpytest.ft import ClassWithTrampoline, ConstexprTrampoline


def test_class_with_trampoline():
Expand All @@ -25,3 +25,7 @@ def fnWithMoveOnlyParam(self, i):

c = PyClassWithTrampoline()
assert ClassWithTrampoline.check_moveonly(c) == 8


def test_constexpr_trampoline():
ConstexprTrampoline()
Loading
0