From 43b9fefbd2dca012c20ffd043a4a9c6189582c82 Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 03:07:27 +0100 Subject: [PATCH 1/3] Use static_assert more actively --- CMakeLists.txt | 7 +++++++ posix.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61af59c9..2b29ed8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,13 @@ endif () # add_definitions(-DFMT_USE_DELETED_FUNCTIONS=1) #endif () +#check_cxx_source_compiles(" +# static_assert(true, \"\"); +# int main(){}" FMT_STATIC_ASSERT) +#if (FMT_STATIC_ASSERT) +# add_definitions(-DFMT_USE_STATIC_ASSERT=1) +#endif () + # GTest doesn't detect with clang. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_definitions(gmock PUBLIC GTEST_USE_OWN_TR1_TUPLE=1) diff --git a/posix.h b/posix.h index 0f31f601..c8075cfb 100644 --- a/posix.h +++ b/posix.h @@ -68,7 +68,8 @@ # define FMT_UNUSED #endif -#if FMT_USE_STATIC_ASSERT +#if FMT_USE_STATIC_ASSERT || FMT_HAS_CPP_ATTRIBUTE(cxx_static_assert) || \ + (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600 # define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message) #else # define FMT_CONCAT_(a, b) FMT_CONCAT(a, b) From 9331533309bd2de4591c02ab86543a93c4bec34f Mon Sep 17 00:00:00 2001 From: carterl Date: Sun, 15 Feb 2015 04:16:23 +0100 Subject: [PATCH 2/3] Use __GXX_EXPERIMENTAL_CXX0X__ for better C++11 detection --- format.h | 14 ++++++++++---- posix.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/format.h b/format.h index ca3eed91..03d4aa24 100644 --- a/format.h +++ b/format.h @@ -86,13 +86,19 @@ # define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif +#ifdef __GNUC__ +# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ +# define FMT_HAS_GXX_CXX11 1 +# endif +#endif + #ifndef FMT_USE_VARIADIC_TEMPLATES // Variadic templates are available in GCC since version 4.4 // (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++ // since version 2013. # define FMT_USE_VARIADIC_TEMPLATES \ (FMT_HAS_FEATURE(cxx_variadic_templates) || \ - (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103) || _MSC_VER >= 1800) + (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800) #endif #ifndef FMT_USE_RVALUE_REFERENCES @@ -103,7 +109,7 @@ # else # define FMT_USE_RVALUE_REFERENCES \ (FMT_HAS_FEATURE(cxx_rvalue_references) || \ - (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600) + (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600) # endif #endif @@ -113,7 +119,7 @@ // Define FMT_USE_NOEXCEPT to make C++ Format use noexcept (C++11 feature). #if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ - (FMT_GCC_VERSION >= 408 && __cplusplus >= 201103) + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) # define FMT_NOEXCEPT noexcept #else # define FMT_NOEXCEPT throw() @@ -122,7 +128,7 @@ // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class #if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \ - (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103L) || _MSC_VER >= 1800 + (FMT_GCC_VERSION >= 404 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1800 # define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&) = delete; \ TypeName& operator=(const TypeName&) = delete diff --git a/posix.h b/posix.h index c8075cfb..a2cf2b13 100644 --- a/posix.h +++ b/posix.h @@ -69,7 +69,7 @@ #endif #if FMT_USE_STATIC_ASSERT || FMT_HAS_CPP_ATTRIBUTE(cxx_static_assert) || \ - (FMT_GCC_VERSION >= 403 && __cplusplus >= 201103) || _MSC_VER >= 1600 + (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600 # define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message) #else # define FMT_CONCAT_(a, b) FMT_CONCAT(a, b) From 9fd566412d44c7f5da6245f1cb7e1a574d23a62e Mon Sep 17 00:00:00 2001 From: root Date: Sun, 15 Feb 2015 15:25:56 +0800 Subject: [PATCH 3/3] Refine --- format.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/format.h b/format.h index 03d4aa24..52e8d5b3 100644 --- a/format.h +++ b/format.h @@ -56,6 +56,9 @@ // many valid cases. # pragma GCC diagnostic ignored "-Wshadow" # endif +# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ +# define FMT_HAS_GXX_CXX11 1 +# endif #else # define FMT_GCC_EXTENSION #endif @@ -86,12 +89,6 @@ # define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif -#ifdef __GNUC__ -# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__ -# define FMT_HAS_GXX_CXX11 1 -# endif -#endif - #ifndef FMT_USE_VARIADIC_TEMPLATES // Variadic templates are available in GCC since version 4.4 // (http://gcc.gnu.org/projects/cxx0x.html) and in Visual C++