1 | // |
2 | // Copyright 2012-2024 Antony Polukhin. |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. (See |
5 | // accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | |
8 | #include <boost/type_index.hpp> |
9 | #include "test_lib.hpp" |
10 | |
11 | #include <boost/core/lightweight_test.hpp> |
12 | |
13 | namespace user_defined_namespace { |
14 | class user_defined{}; |
15 | } |
16 | |
17 | void comparing_types_between_modules() |
18 | { |
19 | boost::typeindex::type_index t_const_int = boost::typeindex::type_id_with_cvr<const int>(); |
20 | boost::typeindex::type_index t_int = boost::typeindex::type_id<int>(); |
21 | |
22 | BOOST_TEST_EQ(t_int, test_lib::get_integer()); |
23 | BOOST_TEST_EQ(t_const_int, test_lib::get_const_integer()); |
24 | BOOST_TEST_NE(t_const_int, test_lib::get_integer()); |
25 | BOOST_TEST_NE(t_int, test_lib::get_const_integer()); |
26 | |
27 | |
28 | boost::typeindex::type_index t_const_userdef |
29 | = boost::typeindex::type_id_with_cvr<const user_defined_namespace::user_defined>(); |
30 | boost::typeindex::type_index t_userdef |
31 | = boost::typeindex::type_id<user_defined_namespace::user_defined>(); |
32 | |
33 | BOOST_TEST_EQ(t_userdef, test_lib::get_user_defined_class()); |
34 | BOOST_TEST_EQ(t_const_userdef, test_lib::get_const_user_defined_class()); |
35 | BOOST_TEST_NE(t_const_userdef, test_lib::get_user_defined_class()); |
36 | BOOST_TEST_NE(t_userdef, test_lib::get_const_user_defined_class()); |
37 | |
38 | |
39 | BOOST_TEST_NE(t_userdef, test_lib::get_integer()); |
40 | BOOST_TEST_NE(t_const_userdef, test_lib::get_integer()); |
41 | BOOST_TEST_NE(t_int, test_lib::get_user_defined_class()); |
42 | BOOST_TEST_NE(t_const_int, test_lib::get_const_user_defined_class()); |
43 | |
44 | // MSVC supports detect_missmatch pragma, but /GR- silently switch disable the link time check. |
45 | // /GR- undefies the _CPPRTTI macro. Using it to detect working detect_missmatch pragma. |
46 | #if !defined(BOOST_HAS_PRAGMA_DETECT_MISMATCH) || !defined(_CPPRTTI) |
47 | test_lib::accept_typeindex(t_int); |
48 | #endif |
49 | } |
50 | |
51 | |
52 | int main() { |
53 | comparing_types_between_modules(); |
54 | |
55 | return boost::report_errors(); |
56 | } |
57 | |
58 | |