| 1 | // Copyright 2020 Peter Dimov |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/describe/members.hpp> |
| 6 | #include <boost/describe/class.hpp> |
| 7 | #include <boost/core/lightweight_test.hpp> |
| 8 | #include <boost/config.hpp> |
| 9 | #include <boost/config/workaround.hpp> |
| 10 | |
| 11 | struct A |
| 12 | { |
| 13 | int m1; |
| 14 | }; |
| 15 | |
| 16 | BOOST_DESCRIBE_STRUCT(A, (), (m1)) |
| 17 | |
| 18 | struct B1: public virtual A |
| 19 | { |
| 20 | int m2; |
| 21 | }; |
| 22 | |
| 23 | BOOST_DESCRIBE_STRUCT(B1, (A), (m2)) |
| 24 | |
| 25 | struct B2: public virtual A |
| 26 | { |
| 27 | int m2; |
| 28 | }; |
| 29 | |
| 30 | BOOST_DESCRIBE_STRUCT(B2, (A), (m2)) |
| 31 | |
| 32 | struct C: public B1, public B2 |
| 33 | { |
| 34 | int m2; |
| 35 | }; |
| 36 | |
| 37 | BOOST_DESCRIBE_STRUCT(C, (B1, B2), (m2)) |
| 38 | |
| 39 | #if !defined(BOOST_DESCRIBE_CXX14) |
| 40 | |
| 41 | #include <boost/config/pragma_message.hpp> |
| 42 | |
| 43 | BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available" ) |
| 44 | int main() {} |
| 45 | |
| 46 | #else |
| 47 | |
| 48 | #include <boost/mp11.hpp> |
| 49 | |
| 50 | int main() |
| 51 | { |
| 52 | using namespace boost::describe; |
| 53 | using namespace boost::mp11; |
| 54 | |
| 55 | { |
| 56 | using L = describe_members<C, mod_public>; |
| 57 | |
| 58 | BOOST_TEST_EQ( mp_size<L>::value, 1 ); |
| 59 | |
| 60 | using D1 = mp_at_c<L, 0>; |
| 61 | |
| 62 | #if !BOOST_WORKAROUND(BOOST_MSVC, < 1940) |
| 63 | // https://developercommunity.visualstudio.com/content/problem/1186002/constexpr-pointer-to-member-has-incorrect-value.html |
| 64 | BOOST_TEST( D1::pointer == &C::m2 ); |
| 65 | #endif |
| 66 | BOOST_TEST_CSTR_EQ( D1::name, "m2" ); |
| 67 | BOOST_TEST_EQ( D1::modifiers, mod_public ); |
| 68 | } |
| 69 | |
| 70 | { |
| 71 | using L = describe_members<C, mod_public | mod_inherited>; |
| 72 | |
| 73 | BOOST_TEST_EQ( mp_size<L>::value, 2 ); |
| 74 | |
| 75 | using D1 = mp_at_c<L, 0>; |
| 76 | using D2 = mp_at_c<L, 1>; |
| 77 | |
| 78 | BOOST_TEST( D1::pointer == &C::A::m1 ); |
| 79 | BOOST_TEST_CSTR_EQ( D1::name, "m1" ); |
| 80 | BOOST_TEST_EQ( D1::modifiers, mod_public | mod_inherited ); |
| 81 | |
| 82 | #if !BOOST_WORKAROUND(BOOST_MSVC, < 1940) |
| 83 | BOOST_TEST( D2::pointer == &C::m2 ); |
| 84 | #endif |
| 85 | BOOST_TEST_CSTR_EQ( D2::name, "m2" ); |
| 86 | BOOST_TEST_EQ( D2::modifiers, mod_public ); |
| 87 | } |
| 88 | |
| 89 | return boost::report_errors(); |
| 90 | } |
| 91 | |
| 92 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 93 | |