diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index b84140fc..c09e6102 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -238,10 +238,12 @@ inline double hsSwapEndianDouble(double dvalue) * StrPrintf(buffer, arrsize(buffer), "%u", value); * ***/ -#define arrsize(a) (sizeof(a) / sizeof((a)[0])) -/* TODO: Use this safer version when MSVC finally supports constexpr */ -//template -//constexpr size_t arrsize(_T (&)[_Sz]) { return _Sz; } +#ifdef HAVE_CONSTEXPR + template + constexpr size_t arrsize(_T(&)[_Sz]) { return _Sz; } +#else +# define arrsize(a) (sizeof(a) / sizeof((a)[0])) +#endif /**************************************************************************** diff --git a/cmake/CompilerChecks.cmake b/cmake/CompilerChecks.cmake index 8b7e21fb..727bcd07 100644 --- a/cmake/CompilerChecks.cmake +++ b/cmake/CompilerChecks.cmake @@ -51,6 +51,11 @@ try_compile(HAVE_GCC_DEPRECATED_ATTR ${PROJECT_BINARY_DIR} COMPILE_DEFINITIONS -DTRY_GCC_ATTR OUTPUT_VARIABLE OUTPUT) +# Look for C++11 constexpr support +try_compile(HAVE_CONSTEXPR ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp + OUTPUT_VARIABLE OUTPUT) + configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake ${PROJECT_BINARY_DIR}/hsCompilerSpecific.h) include_directories(${PROJECT_BINARY_DIR}) diff --git a/cmake/check_constexpr.cpp b/cmake/check_constexpr.cpp new file mode 100644 index 00000000..bff6467e --- /dev/null +++ b/cmake/check_constexpr.cpp @@ -0,0 +1,6 @@ +constexpr int foo() { return 5; } + +int main(int, char **) +{ + return foo(); +} diff --git a/cmake/hsCompilerSpecific.h.cmake b/cmake/hsCompilerSpecific.h.cmake index 02b8e5d1..242c4cf1 100644 --- a/cmake/hsCompilerSpecific.h.cmake +++ b/cmake/hsCompilerSpecific.h.cmake @@ -51,4 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #cmakedefine HAVE_CXX14_DEPRECATED_ATTR #cmakedefine HAVE_GCC_DEPRECATED_ATTR +#cmakedefine HAVE_CONSTEXPR + #endif