Bug 1119071 - Clean up some code used for older unsupported MSVC versions in MFBT; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 08 Jan 2015 10:38:48 -0500
changeset 235728 1ce77cbf99f31888dafcd61c0499b1019e0e859c
parent 235727 b2cf412dad7a0c7f9d1df7b612a5c10b3529e3d9
child 235729 c1dd3c739bf30f5be7ee706ec8e6c641d4ecf164
push id370
push userbsmedberg@mozilla.com
push dateThu, 08 Jan 2015 17:37:37 +0000
reviewersfroydnj
bugs1119071
milestone37.0a1
Bug 1119071 - Clean up some code used for older unsupported MSVC versions in MFBT; r=froydnj
mfbt/Atomics.h
mfbt/Attributes.h
mfbt/Compiler.h
mfbt/NullPtr.h
mfbt/TypedEnumInternal.h
mfbt/tests/TestMaybe.cpp
mfbt/tests/TestTypedEnum.cpp
mfbt/tests/TestUniquePtr.cpp
--- a/mfbt/Atomics.h
+++ b/mfbt/Atomics.h
@@ -37,24 +37,17 @@
     *
     * libc++ <atomic> is only functional with clang.
     */
 #  if MOZ_USING_LIBSTDCXX && MOZ_LIBSTDCXX_VERSION_AT_LEAST(4, 7, 0)
 #    define MOZ_HAVE_CXX11_ATOMICS
 #  elif MOZ_USING_LIBCXX && defined(__clang__)
 #    define MOZ_HAVE_CXX11_ATOMICS
 #  endif
-/*
- * Although Visual Studio 2012's CRT supports <atomic>, its atomic load
- * implementation unnecessarily uses an atomic intrinsic for the less
- * restrictive memory orderings, which can be prohibitively expensive.
- * Therefore, we require at least Visual Studio 2013 for using the CRT
- * (bug 1061764).
- */
-#elif defined(_MSC_VER) && _MSC_VER >= 1800
+#elif defined(_MSC_VER)
 #  if defined(DEBUG)
      /*
       * Provide our own failure code since we're having trouble linking to
       * std::_Debug_message (bug 982310).
       */
 #    define _INVALID_MEMORY_ORDER MOZ_CRASH("Invalid memory order")
 #  endif
 #  define MOZ_HAVE_CXX11_ATOMICS
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -45,28 +45,18 @@
  * 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
  */
-#  if _MSC_VER >= 1800
-#    define MOZ_HAVE_CXX11_DELETE
-#  endif
-#  if _MSC_VER >= 1700
-#    define MOZ_HAVE_CXX11_FINAL         final
-#  else
-#    if defined(__clang__)
-#      error Please do not try to use clang-cl with MSVC10 or below emulation!
-#    endif
-     /* MSVC <= 10 used to spell "final" as "sealed". */
-#    define MOZ_HAVE_CXX11_FINAL         sealed
-#  endif
+#  define MOZ_HAVE_CXX11_DELETE
+#  define MOZ_HAVE_CXX11_FINAL         final
 #  define MOZ_HAVE_CXX11_OVERRIDE
 #  define MOZ_HAVE_NEVER_INLINE          __declspec(noinline)
 #  define MOZ_HAVE_NORETURN              __declspec(noreturn)
 #  ifdef __clang__
      /* clang-cl probably supports constexpr and explicit conversions. */
 #    if __has_extension(cxx_constexpr)
 #      define MOZ_HAVE_CXX11_CONSTEXPR
 #    endif
--- a/mfbt/Compiler.h
+++ b/mfbt/Compiler.h
@@ -26,29 +26,16 @@
 #  if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0)
 #    error "mfbt (and Gecko) require at least gcc 4.4 to build."
 #  endif
 
 #elif defined(_MSC_VER)
 
 #  undef MOZ_IS_MSVC
 #  define MOZ_IS_MSVC 1
-   /*
-    * This macro should simplify MSVC version checking. For example, to check
-    * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`.
-    */
-#  define MOZ_MSVC_VERSION_AT_LEAST(version) \
-     (version == 10 ? _MSC_VER >= 1600 : \
-     (version == 11 ? _MSC_VER >= 1700 : \
-     (version == 12 ? _MSC_VER >= 1800 : \
-     (version == 13 ? _MSC_VER >= 1900 : \
-      0))))
-#  if !MOZ_MSVC_VERSION_AT_LEAST(10)
-#    error "mfbt (and Gecko) require at least MSVC 2010 RTM to build."
-#  endif
 
 #endif
 
 /*
  * The situation with standard libraries is a lot worse than with compilers,
  * particularly as clang and gcc could end up using one of three or so standard
  * libraries, and they may not be up-to-snuff with newer C++11 versions. To
  * detect the library, we're going to include cstddef (which is a small header
--- a/mfbt/NullPtr.h
+++ b/mfbt/NullPtr.h
@@ -20,17 +20,17 @@
 #elif defined(__GNUC__)
 #  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
 #    include "mozilla/Compiler.h"
 #    if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0)
 #      define MOZ_HAVE_CXX11_NULLPTR
 #    endif
 #  endif
 #elif defined(_MSC_VER)
-   // The minimum supported MSVC (10, _MSC_VER 1600) supports nullptr.
+   // The minimum supported MSVC (12, _MSC_VER 1800) supports nullptr.
 #  define MOZ_HAVE_CXX11_NULLPTR
 #endif
 
 namespace mozilla {
 
 /**
  * IsNullPointer<T>::value is true iff T is the type of C++11's nullptr.  If
  * nullptr is emulated, IsNullPointer<T>::value is false for all T.
--- a/mfbt/TypedEnumInternal.h
+++ b/mfbt/TypedEnumInternal.h
@@ -33,19 +33,17 @@
 #  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
 #    if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3)
 #      define MOZ_HAVE_CXX11_ENUM_TYPE
 #      define MOZ_HAVE_CXX11_STRONG_ENUMS
 #    endif
 #  endif
 #elif defined(_MSC_VER)
 #  define MOZ_HAVE_CXX11_ENUM_TYPE
-#  if _MSC_VER >= 1700
-#    define MOZ_HAVE_CXX11_STRONG_ENUMS
-#  endif
+#  define MOZ_HAVE_CXX11_STRONG_ENUMS
 #endif
 
 namespace mozilla {
 
 /*
  * The problem that CastableTypedEnumResult aims to solve is that
  * typed enums are not convertible to bool, and there is no way to make them
  * be, yet user code wants to be able to write
--- a/mfbt/tests/TestMaybe.cpp
+++ b/mfbt/tests/TestMaybe.cpp
@@ -18,28 +18,23 @@ using mozilla::IsSame;
 using mozilla::Maybe;
 using mozilla::Move;
 using mozilla::Nothing;
 using mozilla::Some;
 using mozilla::Swap;
 using mozilla::ToMaybe;
 using mozilla::UniquePtr;
 
-// Work around a bug in Visual Studio 2010 and 2012 that prevents expressions of
+#if MOZ_IS_MSVC
+   template<typename T> struct Identity { typedef T type; };
+#  define DECLTYPE(EXPR) Identity<decltype(EXPR)>::type
+#elif MOZ_IS_GCC
+// Work around a bug in GCC < 4.7 that prevents expressions of
 // the form |decltype(foo)::type| from working. See here:
 // http://stackoverflow.com/questions/14330768/c11-compiler-error-when-using-decltypevar-followed-by-internal-type-of-var
-// GCC < 4.7 also has a similar bug.
-#if MOZ_IS_MSVC
-#  if MOZ_MSVC_VERSION_AT_LEAST(12)
-#    define DECLTYPE(EXPR) decltype(EXPR)
-#  else
-     template<typename T> struct Identity { typedef T type; };
-#    define DECLTYPE(EXPR) Identity<decltype(EXPR)>::type
-#  endif
-#elif MOZ_IS_GCC
 #  if MOZ_GCC_VERSION_AT_LEAST(4, 7, 0)
 #    define DECLTYPE(EXPR) decltype(EXPR)
 #  else
      template<typename T> struct Identity { typedef T type; };
 #    define DECLTYPE(EXPR) Identity<decltype(EXPR)>::type
 #  endif
 #else
 #  define DECLTYPE(EXPR) decltype(EXPR)
--- a/mfbt/tests/TestTypedEnum.cpp
+++ b/mfbt/tests/TestTypedEnum.cpp
@@ -29,19 +29,17 @@
 #    endif
 #  elif defined(__GNUC__)
 #    if defined(__GXX_EXPERIMENTAL_CXX0X__)
 #      if MOZ_GCC_VERSION_AT_LEAST(4, 6, 0)
 #        define MOZ_HAVE_IS_LITERAL
 #      endif
 #    endif
 #  elif defined(_MSC_VER)
-#    if _MSC_VER >= 1700
-#      define MOZ_HAVE_IS_LITERAL
-#    endif
+#    define MOZ_HAVE_IS_LITERAL
 #  endif
 #endif
 
 #if defined(MOZ_HAVE_IS_LITERAL) && defined(MOZ_HAVE_CXX11_CONSTEXPR)
 #include <type_traits>
 template<typename T>
 void
 RequireLiteralType()
--- a/mfbt/tests/TestUniquePtr.cpp
+++ b/mfbt/tests/TestUniquePtr.cpp
@@ -325,34 +325,16 @@ TestReferenceDeleter()
   CHECK(gADestructorCalls == 4);
   CHECK(gBDestructorCalls == 3);
 
   gADestructorCalls = 0;
   gBDestructorCalls = 0;
   return true;
 }
 
-// MSVC10 miscompiles mozilla::RemoveReference<reference to function>, claiming
-// that the partial specializations RemoveReference<T&&> and RemoveReference<T&>
-// both match RemoveReference<FreeSignature> below.  Thus in Mozilla code using
-// UniquePtr with a function reference deleter is forbidden.  But it doesn't
-// hurt to run these tests when the compiler doesn't have problems with this, so
-// do so for anything non-MSVC.
-#if MOZ_IS_MSVC
-   // Technically this could be MOZ_MSVC_VERSION_AT_LEAST(11), but we're not
-   // going to support function deleters as long as we support MSVC10, so it
-   // hardly matters.  In the meantime it's not worth the potential trouble (and
-   // potential for bustage) to run these tests on MSVC>=11.
-#  define SHOULD_TEST_FUNCTION_REFERENCE_DELETER 0
-#else
-#  define SHOULD_TEST_FUNCTION_REFERENCE_DELETER 1
-#endif
-
-#if SHOULD_TEST_FUNCTION_REFERENCE_DELETER
-
 typedef void (&FreeSignature)(void*);
 
 static size_t DeleteIntFunctionCallCount = 0;
 
 static void
 DeleteIntFunction(void* aPtr)
 {
   DeleteIntFunctionCallCount++;
@@ -395,18 +377,16 @@ TestFunctionReferenceDeleter()
     CHECK(DeleteIntFunctionCallCount == 1);
   }
 
   CHECK(DeleteIntFunctionCallCount == 2);
 
   return true;
 }
 
-#endif // SHOULD_TEST_FUNCTION_REFERENCE_DELETER
-
 template<typename T, bool = IsNullPointer<decltype(nullptr)>::value>
 struct AppendNullptrTwice;
 
 template<typename T>
 struct AppendNullptrTwice<T, false>
 {
   AppendNullptrTwice() {}
 
@@ -592,21 +572,19 @@ main()
     return 1;
   }
   if (!TestFreeClass()) {
     return 1;
   }
   if (!TestReferenceDeleter()) {
     return 1;
   }
-#if SHOULD_TEST_FUNCTION_REFERENCE_DELETER
   if (!TestFunctionReferenceDeleter()) {
     return 1;
   }
-#endif
   if (!TestVector()) {
     return 1;
   }
   if (!TestArray()) {
     return 1;
   }
   if (!TestMakeUnique()) {
     return 1;