From 1c2f3a5cd38d8a4ec8c8fad0395b858e82359d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pedro=20Bol=C3=ADvar=20Puente?= Date: Thu, 2 Jun 2022 12:18:16 +0200 Subject: [PATCH 1/2] Add test for case shown by @ajihyf --- test/box/recursive.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/box/recursive.cpp b/test/box/recursive.cpp index 4c8fce07..458ffbaf 100644 --- a/test/box/recursive.cpp +++ b/test/box/recursive.cpp @@ -13,6 +13,7 @@ #include #include +#include #include struct rec_vec @@ -106,3 +107,36 @@ TEST_CASE("recursive set") CHECK(v3.children.count(rec_set{13, {}}) == 1); CHECK(v3.children.count(rec_set{14, {}}) == 0); } + +struct a_type; + +struct b_type +{ + b_type(int a, immer::box val); + int a; + immer::box val; +}; + +struct a_type +{ + a_type(); + // this does not work with std::optional, because it seems like + // `immer::box` is still not considered complete at this point... + boost::optional> b; +}; + +b_type::b_type(int a, immer::box val) + : a(a) + , val(val) +{} + +a_type::a_type() + : b{} +{} + +TEST_CASE("recursive optional") +{ + auto x = a_type{}; + auto y = b_type{42, x}; + CHECK(y.a == 42); +} From 359c3a4ddfa694ba6567ca8ea072ab939c86197c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pedro=20Bol=C3=ADvar=20Puente?= Date: Thu, 2 Jun 2022 12:35:36 +0200 Subject: [PATCH 2/2] Add example with variant, same issue --- test/box/recursive.cpp | 49 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/test/box/recursive.cpp b/test/box/recursive.cpp index 458ffbaf..6ec69897 100644 --- a/test/box/recursive.cpp +++ b/test/box/recursive.cpp @@ -14,6 +14,7 @@ #include #include +#include #include struct rec_vec @@ -108,6 +109,8 @@ TEST_CASE("recursive set") CHECK(v3.children.count(rec_set{14, {}}) == 0); } +namespace example1 { + struct a_type; struct b_type @@ -134,9 +137,51 @@ a_type::a_type() : b{} {} +} // namespace example1 + TEST_CASE("recursive optional") { - auto x = a_type{}; - auto y = b_type{42, x}; + auto x = example1::a_type{}; + auto y = example1::b_type{42, x}; + CHECK(y.a == 42); +} + +namespace example2 { + +struct empty_t +{}; + +struct a_type; + +struct b_type +{ + b_type(int a, immer::box val); + int a; + immer::box val; +}; + +struct a_type +{ + a_type(); + // this does not work with std::variant, because it seems like + // `immer::box` is still not considered complete at this point... + boost::variant b; +}; + +b_type::b_type(int a, immer::box val) + : a(a) + , val(val) +{} + +a_type::a_type() + : b{} +{} + +} // namespace example2 + +TEST_CASE("recursive variant") +{ + auto x = example2::a_type{}; + auto y = example2::b_type{42, x}; CHECK(y.a == 42); }