Skip to content

Commit

Permalink
Fixed missing invoke of dtor when type is pointer type.
Browse files Browse the repository at this point in the history
Now implicit the raw_type will always be used when retrieving the dtor from a type.
First part of the issue: #14
  • Loading branch information
acki-m committed Apr 28, 2016
1 parent 7b31832 commit e7cff15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/rttr/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,14 @@ variant type::create(vector<argument> args) const

destructor type::get_destructor() const
{
return destructor(detail::type_database::instance().get_destructor(*this));
return destructor(detail::type_database::instance().get_destructor(get_raw_type()));
}

/////////////////////////////////////////////////////////////////////////////////////////

bool type::destroy(variant& obj) const
{
return detail::type_database::instance().get_destructor(*this).invoke(obj);
return detail::type_database::instance().get_destructor(get_raw_type()).invoke(obj);
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand Down
22 changes: 17 additions & 5 deletions src/unit_tests/destructor/destructor_invoke_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ TEST_CASE("destructor - invoke", "[destructor]")
type t = type::get<dtor_invoke_test>();
REQUIRE(t.is_valid() == true);

destructor dtor = t.get_destructor();
CHECK(dtor.is_valid() == true);
CHECK(static_cast<bool>(dtor) == true);

SECTION("Invoke positive")
{
variant var = t.create();

CHECK(var.is_valid() == true);

destructor dtor = var.get_type().get_destructor();
CHECK(dtor.is_valid() == true);
CHECK(static_cast<bool>(dtor) == true);

CHECK(dtor.invoke(var) == true);

CHECK(var.is_valid() == false);
Expand All @@ -71,15 +72,26 @@ TEST_CASE("destructor - invoke", "[destructor]")
{
variant var;
CHECK(var.is_valid() == false);

destructor dtor_invalid = type::get_by_name("").get_destructor();
REQUIRE(dtor_invalid.is_valid() == false);

// cannot invoke destructor, because dtor wrapper is invalid
CHECK(dtor_invalid.invoke(var) == false);

// cannot invoke destructor, because given type is invalid
CHECK(dtor.invoke(var) == false);
CHECK(type::get<dtor_invoke_test>().get_destructor().invoke(var) == false);
}
}

////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("destructor - via type", "[destructor]")
{
variant var = type::get<dtor_invoke_test>().create();
REQUIRE(var.get_type() == type::get<dtor_invoke_test*>());
CHECK(var.get_type().destroy(var) == true);
CHECK(var.is_valid() == false);
}

/////////////////////////////////////////////////////////////////////////////////////////

0 comments on commit e7cff15

Please sign in to comment.