Skip to content

Commit

Permalink
Add workaround for MSVC 14-0 bad code generation in slist_test
Browse files Browse the repository at this point in the history
  • Loading branch information
igaztanaga committed May 4, 2023
1 parent f2afafa commit cfc6b4e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 52 deletions.
18 changes: 4 additions & 14 deletions include/boost/intrusive/detail/parent_from_member.hpp
Expand Up @@ -91,25 +91,15 @@ BOOST_INTRUSIVE_FORCEINLINE std::ptrdiff_t offset_from_pointer_to_member(const M
template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
{
return static_cast<Parent*>
(
static_cast<void*>
(
static_cast<char*>(static_cast<void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
)
);
return reinterpret_cast<Parent*>
(reinterpret_cast<std::size_t>(member) - static_cast<std::size_t>(offset_from_pointer_to_member(ptr_to_member)));
}

template<class Parent, class Member>
BOOST_INTRUSIVE_FORCEINLINE const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
{
return static_cast<const Parent*>
(
static_cast<const void*>
(
static_cast<const char*>(static_cast<const void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
)
);
return reinterpret_cast<const Parent*>
( reinterpret_cast<std::size_t>(member) - static_cast<std::size_t>(offset_from_pointer_to_member(ptr_to_member)) );
}

} //namespace detail {
Expand Down
2 changes: 1 addition & 1 deletion include/boost/intrusive/linear_slist_algorithms.hpp
Expand Up @@ -152,7 +152,7 @@ class linear_slist_algorithms
//!
//! <b>Throws</b>: Nothing.
inline static void init_header(node_ptr this_node) BOOST_NOEXCEPT
{ NodeTraits::set_next(this_node, node_ptr ()); }
{ NodeTraits::set_next(this_node, node_ptr()); }

//! <b>Requires</b>: 'p' is the first node of a list.
//!
Expand Down
77 changes: 40 additions & 37 deletions test/slist_test.cpp
Expand Up @@ -355,48 +355,15 @@ void test_slist< ListType, ValueContainer >
TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
}

{ //splice in the same list
list_type testlist1 (values.begin(), values.begin() + 5);

{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

//nop 1
testlist1.splice_after (testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin());
{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

//nop 2
testlist1.splice_after (++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin());
{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

//nop 3
testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++testlist1.before_begin());
{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++testlist1.before_begin());
{ int init_values [] = { 2, 1, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++++testlist1.before_begin());
{ int init_values [] = { 1, 3, 2, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

testlist1.splice_after (++++++++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++++testlist1.before_begin());
{ int init_values [] = { 2, 4, 1, 3, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
}

{ //Now test swap when testlist2 is empty
list_type testlist1 (values.begin(), values.begin() + 2);
list_type testlist2;
BOOST_TEST(testlist2.empty());
testlist1.swap(testlist2);
BOOST_TEST (testlist1.empty());
{ int init_values [] = { 1, 2 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
}
}
{ //Now test swap when testlist1 is empty
list_type testlist2 (values.begin(), values.begin() + 2);
list_type testlist1;
Expand Down Expand Up @@ -457,6 +424,42 @@ void test_slist< ListType, ValueContainer >
{ int init_values [] = { 1 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
}

{ //splice in the same list
list_type testlist1 (values.begin(), values.begin() + 5);

{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

//nop 1
testlist1.splice_after (testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin());
{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

//nop 2
testlist1.splice_after (++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin());
{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

//nop 3
testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++testlist1.before_begin());
{ int init_values [] = { 1, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

#if !defined(BOOST_MSVC) || (BOOST_MSVC != 1900) //Visual 2015 has problems generating this test code
testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++testlist1.before_begin());
{ int init_values [] = { 2, 1, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++++testlist1.before_begin());
{ int init_values [] = { 1, 3, 2, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }

testlist1.splice_after (++++++++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++++testlist1.before_begin());
{ int init_values [] = { 2, 4, 1, 3, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
#endif
}
}

template < typename ListType, typename ValueContainer >
Expand Down Expand Up @@ -683,13 +686,13 @@ int main(int, char* [])
{
// test (plain/smart pointers) x (nonconst/const size) x (void node allocator)
test_main_template<void*, false, true>()();
test_main_template<boost::intrusive::smart_ptr<void>, false, true>()();
test_main_template<void*, true, true>()();

test_main_template<boost::intrusive::smart_ptr<void>, false, true>()();
test_main_template<boost::intrusive::smart_ptr<void>, true, true>()();
// test (bounded pointers) x ((nonconst/const size) x (special node allocator)
test_main_template_bptr< true >()();
test_main_template_bptr< false >()();


return boost::report_errors();
}

0 comments on commit cfc6b4e

Please sign in to comment.