Skip to content

Commit

Permalink
Bug 1120059 - Remove unnecessary MOZ_EXPLICIT_CONVERSION macros. r=jw…
Browse files Browse the repository at this point in the history
…alden

MozReview-Commit-ID: 7CX1VnBRDpk
  • Loading branch information
Michelangelo De Simone committed Jul 13, 2016
1 parent a2193ea commit d1a163a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 56 deletions.
2 changes: 1 addition & 1 deletion gfx/layers/LayerMetricsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class MOZ_STACK_CLASS LayerMetricsWrapper {
return mLayer != nullptr;
}

MOZ_EXPLICIT_CONVERSION operator bool() const
explicit operator bool() const
{
return IsValid();
}
Expand Down
44 changes: 0 additions & 44 deletions mfbt/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,9 @@
* 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.
*
* Even though some versions of MSVC support explicit conversion operators, we
* don't indicate support for them here, due to
* http://stackoverflow.com/questions/20498142/visual-studio-2013-explicit-keyword-bug
*/
# define MOZ_HAVE_NEVER_INLINE __declspec(noinline)
# define MOZ_HAVE_NORETURN __declspec(noreturn)
# if _MSC_VER >= 1900
# define MOZ_HAVE_EXPLICIT_CONVERSION
# endif
# ifdef __clang__
/* clang-cl probably supports explicit conversions. */
# if __has_extension(cxx_explicit_conversions)
# define MOZ_HAVE_EXPLICIT_CONVERSION
# endif
# endif
#elif defined(__clang__)
/*
* Per Clang documentation, "Note that marketing version numbers should not
Expand All @@ -70,19 +57,13 @@
# ifndef __has_extension
# define __has_extension __has_feature /* compatibility, for older versions of clang */
# endif
# if __has_extension(cxx_explicit_conversions)
# define MOZ_HAVE_EXPLICIT_CONVERSION
# endif
# if __has_attribute(noinline)
# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline))
# endif
# if __has_attribute(noreturn)
# define MOZ_HAVE_NORETURN __attribute__((noreturn))
# endif
#elif defined(__GNUC__)
# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
# define MOZ_HAVE_EXPLICIT_CONVERSION
# endif
# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline))
# define MOZ_HAVE_NORETURN __attribute__((noreturn))
#endif
Expand All @@ -97,31 +78,6 @@
# endif
#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/TypedEnumBits.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CastableTypedEnumResult
constexpr operator E() const { return mValue; }

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

constexpr bool operator !() const { return !bool(mValue); }
Expand Down
8 changes: 0 additions & 8 deletions mfbt/tests/TestTypedEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ TestNonConvertibilityForOneType()
{
using mozilla::IsConvertible;

#if defined(MOZ_HAVE_EXPLICIT_CONVERSION)
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");
#endif

static_assert(!IsConvertible<bool, T>::value, "should not be convertible");
static_assert(!IsConvertible<int, T>::value, "should not be convertible");
Expand Down Expand Up @@ -428,18 +426,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
}

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 @@ -572,13 +572,13 @@ class NativeEventData final

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 d1a163a

Please sign in to comment.