From d0edb425f50b9c3c11a417ce15a0d1ca75e225b5 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Thu, 10 Nov 2011 14:19:28 -0800 Subject: [PATCH] Bug 701183 - Make MOZ_DELETE use deleted function syntax in gcc when it's possible to do so without causing a warning. r=cjones --HG-- extra : rebase_source : 6f452c9cc9dcdc772991ee1056975bf7b0b4bb5b --- mfbt/RangedPtr.h | 6 +++--- mfbt/RefPtr.h | 4 ++-- mfbt/Types.h | 33 +++++++++++++++++++++------------ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/mfbt/RangedPtr.h b/mfbt/RangedPtr.h index ce12479800a..82726755dd1 100644 --- a/mfbt/RangedPtr.h +++ b/mfbt/RangedPtr.h @@ -268,9 +268,9 @@ class RangedPtr } private: - RangedPtr(); - T* operator&(); - operator T*() const; + RangedPtr() MOZ_DELETE; + T* operator&() MOZ_DELETE; + operator T*() const MOZ_DELETE; }; } /* namespace mozilla */ diff --git a/mfbt/RefPtr.h b/mfbt/RefPtr.h index 3c9be7ff8af..1f480c3cccf 100644 --- a/mfbt/RefPtr.h +++ b/mfbt/RefPtr.h @@ -269,8 +269,8 @@ private: RefPtr& refPtr; T* tmp; - OutParamRef(); - OutParamRef& operator=(const OutParamRef&); + OutParamRef() MOZ_DELETE; + OutParamRef& operator=(const OutParamRef&) MOZ_DELETE; }; /** diff --git a/mfbt/Types.h b/mfbt/Types.h index d78c87f943f..7b0a00b239e 100644 --- a/mfbt/Types.h +++ b/mfbt/Types.h @@ -93,19 +93,21 @@ /* * MOZ_DELETE, specified immediately prior to the ';' terminating an undefined- * method declaration, attempts to delete that method from the corresponding - * class. An attempt to use the method will produce an error *at link time*, - * not at compile time, in compilers for which this macro can be implemented. - * For example, you can use this macro to produce classes with no implicit copy - * constructor or assignment operator: + * class. An attempt to use the method will always produce an error *at compile + * time* (instead of sometimes as late as link time) when this macro can be + * implemented. For example, you can use MOZ_DELETE to produce classes with no + * implicit copy constructor or assignment operator: * - * struct NonCopyable { + * struct NonCopyable + * { * private: * NonCopyable(const NonCopyable& other) MOZ_DELETE; * void operator=(const NonCopyable& other) MOZ_DELETE; * }; * - * If MOZ_DELETE can't be implemented for the current compiler, it will still - * cause an error, but at link time rather than compile time. + * If MOZ_DELETE can't be implemented for the current compiler, use of the + * annotated method will still cause an error, but the error might occur at link + * time in some cases rather than at compile time. * * MOZ_DELETE relies on C++11 functionality not universally implemented. As a * backstop, method declarations using MOZ_DELETE should be private. @@ -113,11 +115,18 @@ #if defined(__clang__) && (__clang_major__ >= 3 || (__clang_major__ == 2 && __clang_minor__ >= 9)) # define MOZ_DELETE = delete #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) -/* - * g++ >= 4.4 supports deleted functions, but it requires -std=c++0x or - * -std=gnu++0x, and for various reasons we can't use these yet. - */ -# define MOZ_DELETE /* = delete */ + /* + * g++ >= 4.4 requires -std=c++0x or -std=gnu++0x to support deleted functions + * without warnings. These modes are detectable by the experimental macro used + * below or, more standardly, by checking whether __cplusplus has a C++11 or + * greater value. Current versions of g++ do not correctly set __cplusplus, so + * we check both for forward compatibility. + */ +# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L +# define MOZ_DELETE = delete +# else +# define MOZ_DELETE /* = delete */ +# endif #else # define MOZ_DELETE /* unknown C++11 deleted function support */ #endif