Skip to content

Commit

Permalink
Bug 1120059 - Remove MOZ_{HAVE_,}EXPLICIT_CONVERSION. r=Waldo
Browse files Browse the repository at this point in the history
  • Loading branch information
poiru committed Jan 13, 2015
1 parent b988734 commit 3bbc9f5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 46 deletions.
2 changes: 1 addition & 1 deletion gfx/layers/LayerMetricsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class MOZ_STACK_CLASS LayerMetricsWrapper {
return mLayer != nullptr;
}

MOZ_EXPLICIT_CONVERSION operator bool() const
explicit operator bool() const
{
return IsValid();
}
Expand Down
36 changes: 1 addition & 35 deletions mfbt/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
/*
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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<typename T>
* 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
Expand Down
2 changes: 1 addition & 1 deletion mfbt/TypedEnumInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CastableTypedEnumResult
MOZ_CONSTEXPR operator E() const { return mValue; }

template<typename DestinationType>
MOZ_EXPLICIT_CONVERSION MOZ_CONSTEXPR
explicit MOZ_CONSTEXPR
operator DestinationType() const { return DestinationType(mValue); }

MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); }
Expand Down
8 changes: 1 addition & 7 deletions mfbt/tests/TestTypedEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, bool>::value, "should not be convertible");
static_assert(!IsConvertible<T, int>::value, "should not be convertible");
static_assert(!IsConvertible<T, uint64_t>::value, "should not be convertible");
Expand Down Expand Up @@ -435,18 +435,12 @@ void TestNoConversionsBetweenUnrelatedTypes()
static_assert(!IsConvertible<decltype(T1::A), decltype(T2::A | T2::B)>::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<decltype(T1::A | T1::B), T2>::value,
"should not be convertible");
static_assert(!IsConvertible<decltype(T1::A | T1::B), decltype(T2::A)>::value,
"should not be convertible");
static_assert(!IsConvertible<decltype(T1::A | T1::B), decltype(T2::A | T2::B)>::value,
"should not be convertible");
#endif
}

MOZ_BEGIN_ENUM_CLASS(Int8EnumWithHighBits, int8_t)
Expand Down
4 changes: 2 additions & 2 deletions widget/BasicEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,13 +878,13 @@ class WidgetGUIEvent : public WidgetEvent

public:

MOZ_EXPLICIT_CONVERSION operator bool() const
explicit operator bool() const
{
return !mBuffer.IsEmpty();
}

template<typename T>
MOZ_EXPLICIT_CONVERSION operator const T*() const
explicit operator const T*() const
{
return mBuffer.IsEmpty()
? nullptr
Expand Down

0 comments on commit 3bbc9f5

Please sign in to comment.