From 3087b80a778cc5afd5bf57f74dc50f4160ff5252 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 11 Aug 2014 15:11:38 +0400 Subject: [PATCH 1/2] Added BOOST_HAS_PRAGMA_DETECT_MISSMATCH macro --- doc/macro_reference.qbk | 7 +++++++ include/boost/config/compiler/clang.hpp | 1 + include/boost/config/compiler/visualc.hpp | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/doc/macro_reference.qbk b/doc/macro_reference.qbk index 639093ac..d77d88bc 100644 --- a/doc/macro_reference.qbk +++ b/doc/macro_reference.qbk @@ -399,6 +399,13 @@ containing header should be included only once while preprocessing the current translation unit. The pragma may improve compile times of large projects with some compilers. ]] +[[`BOOST_HAS_PRAGMA_DETECT_MISSMATCH`][Compiler][ +The compiler recognizes the `#pragma detect_mismatch("name", "value")` directive which tells that the +link stage should be terminated with error if values for provided `"name"` missmatch. +This pragma may be a help in preventing ODR violations and ensuring that different modules +are compiled with same flags. +]] + [[`BOOST_HAS_PTHREAD_DELAY_NP`][Platform][ The platform has the POSIX API `pthread_delay_np`. ]] diff --git a/include/boost/config/compiler/clang.hpp b/include/boost/config/compiler/clang.hpp index 6a178242..3cf6cc82 100644 --- a/include/boost/config/compiler/clang.hpp +++ b/include/boost/config/compiler/clang.hpp @@ -9,6 +9,7 @@ // Clang compiler setup. #define BOOST_HAS_PRAGMA_ONCE +#define BOOST_HAS_PRAGMA_DETECT_MISSMATCH // When compiling with clang before __has_extension was defined, // even if one writes 'defined(__has_extension) && __has_extension(xxx)', diff --git a/include/boost/config/compiler/visualc.hpp b/include/boost/config/compiler/visualc.hpp index cef7a4b7..9891c418 100644 --- a/include/boost/config/compiler/visualc.hpp +++ b/include/boost/config/compiler/visualc.hpp @@ -36,6 +36,9 @@ #define BOOST_HAS_PRAGMA_ONCE +// Will be undefined for old compilers lower in this file +#define BOOST_HAS_PRAGMA_DETECT_MISSMATCH + // // versions check: // we don't support Visual C++ prior to version 7.1: @@ -59,6 +62,7 @@ #if _MSC_VER < 1500 // 140X == VC++ 8.0 # define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +# undef BOOST_HAS_PRAGMA_DETECT_MISSMATCH #endif #if _MSC_VER < 1600 // 150X == VC++ 9.0 From 6ea485e9f10c54abb3e0c705bdbad7ba3c3207a1 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 18 Aug 2014 20:35:42 +0400 Subject: [PATCH 2/2] Fix BOOST_HAS_PRAGMA_DETECT_MISSMATCH detection for Clang --- include/boost/config/compiler/clang.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/boost/config/compiler/clang.hpp b/include/boost/config/compiler/clang.hpp index 3cf6cc82..d6ea0cdd 100644 --- a/include/boost/config/compiler/clang.hpp +++ b/include/boost/config/compiler/clang.hpp @@ -9,7 +9,15 @@ // Clang compiler setup. #define BOOST_HAS_PRAGMA_ONCE -#define BOOST_HAS_PRAGMA_DETECT_MISSMATCH + +// Detecting `-fms-extension` compiler flag assuming that _MSC_VER defined when that flag is used. +#if defined (_MSC_VER) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4)) + // Ignoring the checks on APPLE platform because someone made __clang_major__ equal to + // LLVM version rather than compiler version. +# ifndef __APPLE__ +# define BOOST_HAS_PRAGMA_DETECT_MISSMATCH +# endif +#endif // When compiling with clang before __has_extension was defined, // even if one writes 'defined(__has_extension) && __has_extension(xxx)',