Use detect_mismatch pragma when possible (refs #10404 in track)

This commit is contained in:
Antony Polukhin
2014-08-26 14:41:54 +04:00
parent 99f58714d1
commit 242d9a0bed
6 changed files with 23 additions and 4 deletions

View File

@ -463,5 +463,6 @@ In order of helping and advising:
* Peter Dimov for writing source codes in late 2007, that gave me an idea of how to emulate RTTI.
* Agustín Bergé K-ballo for helping with docs and fixing a lot of typos.
* Niall Douglas for generating a lot of great ideas, reviewing the sources and being the review manager for the library.
* All the library reviewers, especially Andrey Semashev, for making good notes and proposing improvements to the library.
[endsect]

View File

@ -22,14 +22,27 @@
#if defined(BOOST_TYPE_INDEX_USER_TYPEINDEX)
# include BOOST_TYPE_INDEX_USER_TYPEINDEX
# ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
# pragma detect_mismatch( "boost__type_index__abi", "user defined type_index class is used: " BOOST_STRINGIZE(BOOST_TYPE_INDEX_USER_TYPEINDEX))
# endif
#elif (!defined(BOOST_NO_RTTI) && !defined(BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY)) || defined(BOOST_MSVC)
# include <boost/type_index/stl_type_index.hpp>
# ifdef BOOST_NO_RTTI
# include <boost/type_index/detail/stl_register_class.hpp>
# ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
# pragma detect_mismatch( "boost__type_index__abi", "RTTI is off - typeid() is used only for templates")
# endif
# else
# ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
# pragma detect_mismatch( "boost__type_index__abi", "RTTI is used")
# endif
# endif
#else
# include <boost/type_index/ctti_type_index.hpp>
# include <boost/type_index/detail/ctti_register_class.hpp>
# ifdef BOOST_HAS_PRAGMA_DETECT_MISMATCH
# pragma detect_mismatch( "boost__type_index__abi", "RTTI is off - using CTTI")
# endif
#endif
#ifndef BOOST_TYPE_INDEX_REGISTER_CLASS

View File

@ -51,8 +51,8 @@ test-suite type_index
# Mixing RTTI on and off
[ link-fail testing_crossmodule.cpp test_lib_rtti : $(nortti) : link_fail_nortti_rtti ]
# MSVC sometimes overrides the /GR-, that's why the following tests is disabled
#[ link-fail testing_crossmodule.cpp test_lib_nortti : : link_fail_rtti_nortti ]
# MSVC sometimes overrides the /GR-, without `detect_missmatch` this test may link
[ link-fail testing_crossmodule.cpp test_lib_nortti : : link_fail_rtti_nortti ]
[ run testing_crossmodule.cpp test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ]
[ run testing_crossmodule.cpp test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ]
;

View File

@ -31,9 +31,10 @@ boost::typeindex::type_index get_const_user_defined_class() {
return boost::typeindex::type_id_with_cvr<const user_defined_namespace::user_defined>();
}
#ifndef BOOST_HAS_PRAGMA_DETECT_MISMATCH
// Just do nothing
void accept_typeindex(const boost::typeindex::type_index&) {}
#endif
}

View File

@ -31,8 +31,10 @@ TEST_LIB_DECL boost::typeindex::type_index get_user_defined_class();
TEST_LIB_DECL boost::typeindex::type_index get_const_integer();
TEST_LIB_DECL boost::typeindex::type_index get_const_user_defined_class();
#ifndef BOOST_HAS_PRAGMA_DETECT_MISMATCH
// This is required for checking RTTI on/off linkage
TEST_LIB_DECL void accept_typeindex(const boost::typeindex::type_index&);
#endif
}

View File

@ -44,7 +44,9 @@ void comparing_types_between_modules()
BOOST_CHECK_NE(t_int, test_lib::get_user_defined_class());
BOOST_CHECK_NE(t_const_int, test_lib::get_const_user_defined_class());
test_lib::accept_typeindex(t_int);
#ifndef BOOST_HAS_PRAGMA_DETECT_MISMATCH
test_lib::accept_typeindex(t_int);
#endif
}