Bug 782647. Move the nullptr workaround macros to MFBT so that it can be shared. r=waldo
This also changes the header to use compiler detection instead of a
configure test. This makes the header more portable because
it doesn't require the configure infrastructure.
--- a/configure.in
+++ b/configure.in
@@ -749,19 +749,16 @@ if test -n "$_WIN32_MSVC"; then
SKIP_COMPILER_CHECKS=1
SKIP_LIBRARY_CHECKS=1
# Since we're skipping compiler and library checks, hard-code
# some facts here.
AC_DEFINE(HAVE_IO_H)
AC_DEFINE(HAVE_SETBUF)
AC_DEFINE(HAVE_ISATTY)
- if test $_MSC_VER -ge 1600; then
- AC_DEFINE(HAVE_NULLPTR)
- fi
fi
fi # COMPILE_ENVIRONMENT
AC_SUBST(MIDL_FLAGS)
AC_SUBST(_MSC_VER)
AC_SUBST(GNU_AS)
@@ -2799,31 +2796,16 @@ dnl Note that we assume that mac & win32
else
WCHAR_CFLAGS="-fshort-wchar"
fi
else
CXXFLAGS=$_SAVE_CXXFLAGS
fi
fi
-dnl Check for nullptr (bug 626472)
-AC_LANG_CPLUSPLUS
-AC_MSG_CHECKING(for nullptr)
-AC_CACHE_VAL(ac_cv_nullptr,
- [AC_TRY_COMPILE([],
- [int* foo = nullptr;],
- [ac_cv_nullptr=true],
- [ac_cv_nullptr=false])])
-if test "$ac_cv_nullptr" = true ; then
- AC_DEFINE(HAVE_NULLPTR)
- AC_MSG_RESULT(yes)
-else
- AC_MSG_RESULT(no)
-fi
-
AC_LANG_C
dnl Check for .hidden assembler directive and visibility attribute.
dnl Borrowed from glibc configure.in
dnl ===============================================================
if test "$GNU_CC"; then
AC_CACHE_CHECK(for visibility(hidden) attribute,
ac_cv_visibility_hidden,
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -1,34 +1,18 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_TYPES_H_
#define MOZILLA_GFX_TYPES_H_
-/**
- * Use C++11 nullptr if available; otherwise use a C++ typesafe template; and
- * for C, fall back to longs. See bugs 547964 and 626472.
- * Copy and paste job from nscore.h, see bug 781943
- */
-#if defined(MOZ_GFX) && !defined(HAVE_NULLPTR)
-#ifndef __cplusplus
-# define nullptr ((void*)0)
-#elif defined(__GNUC__)
-# define nullptr __null
-#elif defined(_WIN64)
-# define nullptr 0LL
-#else
-# define nullptr 0L
-#endif
-#endif /* defined(MOZ_GFX) && !defined(HAVE_NULLPTR) */
-
#include "mozilla/StandardInteger.h"
+#include "mozilla/NullPtr.h"
#include <stddef.h>
namespace mozilla {
namespace gfx {
typedef float Float;
new file mode 100644
--- /dev/null
+++ b/mfbt/NullPtr.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Implements a workaround for compilers which do not support the C++11 nullptr
+ * constant.
+ */
+
+#ifndef mozilla_NullPtr_h_
+#define mozilla_NullPtr_h_
+
+#if defined(__clang__)
+# ifndef __has_extension
+# define __has_extension __has_feature
+# endif
+# if __has_extension(cxx_nullptr)
+# define MOZ_HAVE_CXX11_NULLPTR
+# endif
+#elif defined(__GNUC__)
+# if defined(_GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
+# if (__GNUC__ * 1000 + __GNU_MINOR__) >= 4006
+# define MOZ_HAVE_CXX11_NULLPTR
+# endif
+# endif
+#elif _MSC_VER >= 1600
+# define MOZ_HAVE_CXX11_NULLPTR
+#endif
+
+/**
+ * Use C++11 nullptr if available; otherwise use __null for gcc, or a 0 literal
+ * with the correct size to match the size of a pointer on a given platform.
+ */
+
+#ifndef MOZ_HAVE_CXX11_NULLPTR
+# if defined(__GNUC__)
+# define nullptr __null
+# elif defined(_WIN64)
+# define nullptr 0LL
+# else
+# define nullptr 0L
+# endif
+#endif
+
+#endif /* mozilla_NullPtr_h_ */
--- a/mfbt/exported_headers.mk
+++ b/mfbt/exported_headers.mk
@@ -16,16 +16,17 @@ EXPORTS_mozilla += \
Constants.h \
FloatingPoint.h \
GuardObjects.h \
HashFunctions.h \
Likely.h \
LinkedList.h \
MathAlgorithms.h \
MSStdInt.h \
+ NullPtr.h \
RangedPtr.h \
RefPtr.h \
Scoped.h \
StandardInteger.h \
SHA1.h \
ThreadLocal.h \
TypeTraits.h \
Types.h \
--- a/xpcom/base/nscore.h
+++ b/xpcom/base/nscore.h
@@ -21,16 +21,18 @@
#endif
/**
* Incorporate the integer data types which XPCOM uses.
*/
#include "mozilla/StandardInteger.h"
#include "stddef.h"
+#include "mozilla/NullPtr.h"
+
/*
* This is for functions that are like malloc_usable_size. Such functions are
* used for measuring the size of data structures.
*/
typedef size_t(*nsMallocSizeOfFun)(const void *p);
/* Core XPCOM declarations. */
@@ -319,32 +321,16 @@ typedef uint32_t nsresult;
* IUnknown.
*/
#ifdef XP_WIN
typedef unsigned long nsrefcnt;
#else
typedef uint32_t nsrefcnt;
#endif
-/**
- * Use C++11 nullptr if available; otherwise use a C++ typesafe template; and
- * for C, fall back to longs. See bugs 547964 and 626472.
- */
-#ifndef HAVE_NULLPTR
-#ifndef __cplusplus
-# define nullptr ((void*)0)
-#elif defined(__GNUC__)
-# define nullptr __null
-#elif defined(_WIN64)
-# define nullptr 0LL
-#else
-# define nullptr 0L
-#endif
-#endif /* defined(HAVE_NULLPTR) */
-
#include "nsError.h"
/* ------------------------------------------------------------------------ */
/* Casting macros for hiding C++ features from older compilers */
/* under VC++ (Windows), we don't have autoconf yet */
#if defined(_MSC_VER)
#define HAVE_CPP_2BYTE_WCHAR_T