From a17884f425f14fbaba88a14410a8332f4ed04e57 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 16 Sep 2015 18:27:48 +0100 Subject: [PATCH] Add support for __unreachable_return on clang and GCC. See https://svn.boost.org/trac/boost/ticket/11661. --- include/boost/config/compiler/clang.hpp | 5 +++++ include/boost/config/compiler/gcc.hpp | 5 +++++ include/boost/config/suffix.hpp | 10 ++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/boost/config/compiler/clang.hpp b/include/boost/config/compiler/clang.hpp index 47ea65b0..897f9f07 100644 --- a/include/boost/config/compiler/clang.hpp +++ b/include/boost/config/compiler/clang.hpp @@ -255,6 +255,11 @@ // All versions with __cplusplus above this value seem to support this: # define BOOST_NO_CXX14_DIGIT_SEPARATORS #endif +// +// __builtin_unreachable: +#if defined(__has_builtin) && __has_builtin(__builtin_unreachable) +#define BOOST_UNREACHABLE_RETURN(x) __builtin_unreachable(); +#endif // Unused attribute: diff --git a/include/boost/config/compiler/gcc.hpp b/include/boost/config/compiler/gcc.hpp index 07147ee0..6d32b5bb 100644 --- a/include/boost/config/compiler/gcc.hpp +++ b/include/boost/config/compiler/gcc.hpp @@ -278,6 +278,11 @@ #if __GNUC__ >= 4 # define BOOST_ATTRIBUTE_UNUSED __attribute__((unused)) #endif +// +// __builtin_unreachable: +#if BOOST_GCC_VERSION >= 40800 +#define BOOST_UNREACHABLE_RETURN(x) __builtin_unreachable(); +#endif #ifndef BOOST_COMPILER # define BOOST_COMPILER "GNU C++ version " __VERSION__ diff --git a/include/boost/config/suffix.hpp b/include/boost/config/suffix.hpp index 91a62acb..17bf1020 100644 --- a/include/boost/config/suffix.hpp +++ b/include/boost/config/suffix.hpp @@ -444,10 +444,12 @@ namespace std { // is defined, in which case it evaluates to return x; Use when you have a return // statement that can never be reached. -#ifdef BOOST_NO_UNREACHABLE_RETURN_DETECTION -# define BOOST_UNREACHABLE_RETURN(x) return x; -#else -# define BOOST_UNREACHABLE_RETURN(x) +#ifndef BOOST_UNREACHABLE_RETURN +# ifdef BOOST_NO_UNREACHABLE_RETURN_DETECTION +# define BOOST_UNREACHABLE_RETURN(x) return x; +# else +# define BOOST_UNREACHABLE_RETURN(x) +# endif #endif // BOOST_DEDUCED_TYPENAME workaround ------------------------------------------//