From 2eef573656d40d397842f72ad02be2744222ec8f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 14 Feb 2015 23:22:14 +0800 Subject: [PATCH] Use explicitly deleted functions to make types non-copyable --- CMakeLists.txt | 11 +++++++++++ format.h | 13 ++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82843b2f..61af59c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,17 @@ endif () # add_definitions(-DFMT_USE_NOEXCEPT=1) #endif () +#check_cxx_source_compiles(" +# struct C{ +# C()=delete; +# C(const C&)=delete; +# C& operator=(const C&)=delete; +# }; +# int main(){}" FMT_DELETED_FUNCTIONS) +#if (FMT_DELETED_FUNCTIONS) +# add_definitions(-DFMT_USE_DELETED_FUNCTIONS=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/format.h b/format.h index 78a354f0..ca3eed91 100644 --- a/format.h +++ b/format.h @@ -121,9 +121,16 @@ // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class -#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) +#if FMT_USE_DELETED_FUNCTIONS || FMT_HAS_FEATURE(cxx_deleted_functions) || \ + (FMT_GCC_VERSION >= 404 && __cplusplus >= 201103L) || _MSC_VER >= 1800 +# define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&) = delete; \ + TypeName& operator=(const TypeName&) = delete +#else +# define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + TypeName& operator=(const TypeName&) +#endif namespace fmt {