diff --git a/gfx/layers/LayerMetricsWrapper.h b/gfx/layers/LayerMetricsWrapper.h index b390b5eda95fd..ee1c0655156ac 100644 --- a/gfx/layers/LayerMetricsWrapper.h +++ b/gfx/layers/LayerMetricsWrapper.h @@ -168,7 +168,7 @@ class MOZ_STACK_CLASS LayerMetricsWrapper { return mLayer != nullptr; } - MOZ_EXPLICIT_CONVERSION operator bool() const + explicit operator bool() const { return IsValid(); } diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index ce536038ca573..f1767272343d6 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -55,13 +55,10 @@ # define MOZ_HAVE_NEVER_INLINE __declspec(noinline) # define MOZ_HAVE_NORETURN __declspec(noreturn) # ifdef __clang__ - /* clang-cl probably supports constexpr and explicit conversions. */ + /* clang-cl probably supports constexpr. */ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif -# if __has_extension(cxx_explicit_conversions) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif # endif #elif defined(__clang__) /* @@ -75,9 +72,6 @@ # if __has_extension(cxx_constexpr) # define MOZ_HAVE_CXX11_CONSTEXPR # endif -# if __has_extension(cxx_explicit_conversions) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif # if __has_extension(cxx_override_control) # define MOZ_HAVE_CXX11_OVERRIDE # define MOZ_HAVE_CXX11_FINAL final @@ -97,9 +91,6 @@ # if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0) # define MOZ_HAVE_CXX11_CONSTEXPR # endif -# if MOZ_GCC_VERSION_AT_LEAST(4, 5, 0) -# define MOZ_HAVE_EXPLICIT_CONVERSION -# endif # else /* __final is a non-C++11 GCC synonym for 'final', per GCC r176655. */ # if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0) @@ -138,31 +129,6 @@ # define MOZ_CONSTEXPR_VAR const #endif -/* - * MOZ_EXPLICIT_CONVERSION is a specifier on a type conversion - * overloaded operator that declares that a C++11 compiler should restrict - * this operator to allow only explicit type conversions, disallowing - * implicit conversions. - * - * Example: - * - * template - * class Ptr - * { - * T* mPtr; - * MOZ_EXPLICIT_CONVERSION operator bool() const - * { - * return mPtr != nullptr; - * } - * }; - * - */ -#ifdef MOZ_HAVE_EXPLICIT_CONVERSION -# define MOZ_EXPLICIT_CONVERSION explicit -#else -# define MOZ_EXPLICIT_CONVERSION /* no support */ -#endif - /* * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * method decorated with it must never be inlined, even if the compiler would diff --git a/mfbt/TypedEnumInternal.h b/mfbt/TypedEnumInternal.h index 5af19e20202ec..4ef0767650896 100644 --- a/mfbt/TypedEnumInternal.h +++ b/mfbt/TypedEnumInternal.h @@ -81,7 +81,7 @@ class CastableTypedEnumResult MOZ_CONSTEXPR operator E() const { return mValue; } template - MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR + explicit MOZ_CONSTEXPR operator DestinationType() const { return DestinationType(mValue); } MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); } diff --git a/mfbt/tests/TestTypedEnum.cpp b/mfbt/tests/TestTypedEnum.cpp index f08024325aeba..e9f39bf9bba20 100644 --- a/mfbt/tests/TestTypedEnum.cpp +++ b/mfbt/tests/TestTypedEnum.cpp @@ -160,7 +160,7 @@ TestNonConvertibilityForOneType() { using mozilla::IsConvertible; -#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) && defined(MOZ_HAVE_EXPLICIT_CONVERSION) +#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) static_assert(!IsConvertible::value, "should not be convertible"); static_assert(!IsConvertible::value, "should not be convertible"); static_assert(!IsConvertible::value, "should not be convertible"); @@ -435,18 +435,12 @@ void TestNoConversionsBetweenUnrelatedTypes() static_assert(!IsConvertible::value, "should not be convertible"); - // The following are #ifdef MOZ_HAVE_EXPLICIT_CONVERSION because without - // support for explicit conversion operators, we can't easily have these bad - // conversions completely removed. They still do fail to compile in practice, - // but not in a way that we can static_assert on. -#ifdef MOZ_HAVE_EXPLICIT_CONVERSION static_assert(!IsConvertible::value, "should not be convertible"); static_assert(!IsConvertible::value, "should not be convertible"); static_assert(!IsConvertible::value, "should not be convertible"); -#endif } MOZ_BEGIN_ENUM_CLASS(Int8EnumWithHighBits, int8_t) diff --git a/widget/BasicEvents.h b/widget/BasicEvents.h index f55ce9bfafdfd..fd08acd6549ac 100644 --- a/widget/BasicEvents.h +++ b/widget/BasicEvents.h @@ -878,13 +878,13 @@ class WidgetGUIEvent : public WidgetEvent public: - MOZ_EXPLICIT_CONVERSION operator bool() const + explicit operator bool() const { return !mBuffer.IsEmpty(); } template - MOZ_EXPLICIT_CONVERSION operator const T*() const + explicit operator const T*() const { return mBuffer.IsEmpty() ? nullptr