diff --git a/configure.ac b/configure.ac index 5f4125c0..f3a0c2e3 100644 --- a/configure.ac +++ b/configure.ac @@ -177,6 +177,9 @@ AM_CONDITIONAL(USE_LATEX, test "${LATEX}" != "no") AM_CONDITIONAL(USE_DOT, test "${DOT}" != "no") +dnl C++11 mode +LOL_TRY_CXXFLAGS(-std=c++11, [AM_CXXFLAGS="${AM_CXXFLAGS} -std=c++11"]) + dnl No exceptions LOL_TRY_CXXFLAGS(-fno-exceptions, [AM_CXXFLAGS="${AM_CXXFLAGS} -fno-exceptions"]) LOL_TRY_CXXFLAGS(-fno-rtti, [AM_CXXFLAGS="${AM_CXXFLAGS} -fno-rtti"]) diff --git a/src/core.h b/src/core.h index ff641f72..81543d52 100644 --- a/src/core.h +++ b/src/core.h @@ -16,7 +16,9 @@ #if !defined __LOL_CORE_H__ #define __LOL_CORE_H__ -// System and CPU features +/* + * System and CPU features. + */ #undef LOL_FEATURE_THREADS #undef LOL_FEATURE_CHEAP_BRANCHES #undef LOL_FEATURE_VERY_CHEAP_BRANCHES @@ -29,6 +31,43 @@ # define LOL_FEATURE_CHEAP_BRANCHES 1 #endif + +/* + * Check for C++11 features. + */ +#undef LOL_FEATURE_CXX11_CONSTEXPR +#undef LOL_FEATURE_CXX11_ISNAN + +#if defined __GNUC__ /* GCC */ +# if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L +# define LOL_FEATURE_CXX11_CONSTEXPR 1 +# define LOL_FEATURE_CXX11_ISNAN 1 +# endif + +#elif defined _MSC_VER /* Visual Studio */ + /* Even Visual Studio 2012 doesn't support constexpr. Idiots. */ + +#elif defined __has_feature /* Clang */ +# if __has_feature(cxx_constexpr) +# define LOL_FEATURE_CXX11_CONSTEXPR 1 +# endif +#endif + +#if LOL_FEATURE_CXX11_CONSTEXPR +# define LOL_CONSTEXPR constexpr +# define LOL_CONSTEXPR_DECLARATION(type, name, value) \ + static type constexpr name = value; +# define LOL_CONSTEXPR_DEFINITION(type, name, value) \ + /* Nothing */ +#else +# define LOL_CONSTEXPR /* Nothing */ +# define LOL_CONSTEXPR_DECLARATION(type, name, value) \ + static type const name; +# define LOL_CONSTEXPR_DEFINITION(type, name, value) \ + type const name = value; +#endif + + // Optimisation helpers #if defined __GNUC__ # define __likely(x) __builtin_expect(!!(x), 1) @@ -68,7 +107,7 @@ #if defined __FAST_MATH__ # undef isnan #endif -#if !defined isnan +#if !defined isnan && !defined LOL_FEATURE_CXX11_ISNAN # define isnan isnan # include static inline int isnan(float f)