Skip to content

Commit

Permalink
fix slot assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Aug 29, 2024
1 parent c7b8dee commit 650e669
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions tests/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ const auto& get_method(const Compiler& comp, const method_info& info) {
}

#define ADD_METHOD(CLASS) \
YOMM2_STATIC(method<CLASS, void(virtual_<CLASS&>), test_policy>); \
auto& BOOST_PP_CAT(m_, CLASS) = \
method<CLASS, void(virtual_<CLASS&>), test_policy>::fn;

Expand All @@ -659,9 +658,6 @@ BOOST_AUTO_TEST_CASE(test_assign_slots) {
{
using test_policy = test_policy_<__COUNTER__>;

// Remove methods added via static initialization.
test_policy::methods.clear();

// B
// / \
// AB D
Expand All @@ -670,41 +666,58 @@ BOOST_AUTO_TEST_CASE(test_assign_slots) {
auto comp = update<test_policy>();

BOOST_TEST(get_class<B>(comp)->vtbl.size() == 0);
}

{
using test_policy = test_policy_<__COUNTER__>;
// A star after a class indicates that a method declaration exists for
// that class.
//
// B
// / \
// AB* D

YOMM2_STATIC(use_classes<B, AB, D, test_policy>);
ADD_METHOD(AB);
comp = update<test_policy>();
auto comp = update<test_policy>();

BOOST_TEST(get_class<B>(comp)->vtbl.size() == 0);
BOOST_TEST(get_class<AB>(comp)->vtbl.size() == 1);
BOOST_TEST(get_class<D>(comp)->vtbl.size() == 0);
BOOST_REQUIRE(get_method(comp, m_AB).slots == size_vec(0));
BOOST_TEST(get_method(comp, m_AB).slots == size_vec(0));
}

{
using test_policy = test_policy_<__COUNTER__>;

// B
// / \
// AB* D*

YOMM2_STATIC(use_classes<B, AB, D, test_policy>);
ADD_METHOD(AB);
ADD_METHOD(D);
comp = update<test_policy>();
auto comp = update<test_policy>();

BOOST_TEST(get_class<B>(comp)->vtbl.size() == 0);
BOOST_TEST(get_class<AB>(comp)->vtbl.size() == 1);
BOOST_TEST(get_method(comp, m_AB).slots == size_vec(0));
BOOST_TEST(get_class<D>(comp)->vtbl.size() == 1);
BOOST_TEST(get_method(comp, m_AB).slots == size_vec(0));
}

{
using test_policy = test_policy_<__COUNTER__>;

// B*
// / \
// AB* D*

YOMM2_STATIC(use_classes<B, AB, D, test_policy>);
ADD_METHOD(B);
comp = update<test_policy>();
ADD_METHOD(AB);
ADD_METHOD(D);
auto comp = update<test_policy>();

BOOST_TEST(get_class<B>(comp)->vtbl.size() == 1);
BOOST_TEST(get_method(comp, m_B).slots == size_vec(0));
Expand Down

0 comments on commit 650e669

Please sign in to comment.