From 093e897c1b002c4e8977095399a3208885d13229 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Sat, 7 Apr 2001 17:25:16 +0000 Subject: [PATCH] Fix bustage on VC++ and gcc 2.7.2.x caused by incorrect overload resolution. --- configure.in | 45 +++++++++++++++++++++++++++++++++++++++++++ xpcom/base/nsCOMPtr.h | 10 +++++++++- xpcom/glue/nsCOMPtr.h | 10 +++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index c29badbe8ef..c5b59085448 100644 --- a/configure.in +++ b/configure.in @@ -3487,6 +3487,51 @@ if test "$_PEDANTIC"; then esac fi +dnl Autoconf test for gcc 2.7.2.x (and maybe others?) so that we don't +dnl provide non-const forms of the operator== for comparing nsCOMPtrs to +dnl raw pointers in nsCOMPtr.h. (VC++ has the same bug.) + +AC_LANG_CPLUSPLUS +_SAVE_CXXFLAGS=$CXXFLAGS +CXXFLAGS="$CXXFLAGS ${_WARNINGS_CXXFLAGS}" + +AC_CACHE_CHECK(for correct overload resolution with const and templates, + ac_nscap_nonconst_opeq_bug, + [AC_TRY_COMPILE([ + template + class Pointer + { + public: + T* myPtr; + }; + + template + int operator==(const Pointer& rhs, U* lhs) + { + return rhs.myPtr == lhs; + } + + template + int operator==(const Pointer& rhs, const U* lhs) + { + return rhs.myPtr == lhs; + } + ], + [ + Pointer foo; + const int* bar; + return foo == bar; + ], + ac_nscap_nonconst_opeq_bug="no", + ac_nscap_nonconst_opeq_bug="yes")]) + +AC_LANG_C +CXXFLAGS="$_SAVE_CXXFLAGS" + +if test "$ac_nscap_nonconst_opeq_bug" = "yes" ; then + AC_DEFINE(NSCAP_DONT_PROVIDE_NONCONST_OPEQ) +fi + dnl pass -Wno-long-long to the compiler MOZ_ARG_ENABLE_BOOL(long-long-warning, [ --enable-long-long-warning diff --git a/xpcom/base/nsCOMPtr.h b/xpcom/base/nsCOMPtr.h index ab44a71634d..955f0fae459 100644 --- a/xpcom/base/nsCOMPtr.h +++ b/xpcom/base/nsCOMPtr.h @@ -1193,7 +1193,15 @@ operator!=( const U* lhs, const nsCOMPtr& rhs ) // better conversion for the other argument, define additional // |operator==| without the |const| on the raw pointer. // See bug 65664 for details. -#ifndef CANT_RESOLVE_CPP_CONST_AMBIGUITY + +// This is defined by an autoconf test, but VC++ also has a bug that +// prevents us from using these. (It also, fortunately, has the bug +// that we don't need them either.) +#ifdef _MSC_VER +#define NSCAP_DONT_PROVIDE_NONCONST_OPEQ +#endif + +#ifndef NSCAP_DONT_PROVIDE_NONCONST_OPEQ template inline NSCAP_BOOL diff --git a/xpcom/glue/nsCOMPtr.h b/xpcom/glue/nsCOMPtr.h index ab44a71634d..955f0fae459 100644 --- a/xpcom/glue/nsCOMPtr.h +++ b/xpcom/glue/nsCOMPtr.h @@ -1193,7 +1193,15 @@ operator!=( const U* lhs, const nsCOMPtr& rhs ) // better conversion for the other argument, define additional // |operator==| without the |const| on the raw pointer. // See bug 65664 for details. -#ifndef CANT_RESOLVE_CPP_CONST_AMBIGUITY + +// This is defined by an autoconf test, but VC++ also has a bug that +// prevents us from using these. (It also, fortunately, has the bug +// that we don't need them either.) +#ifdef _MSC_VER +#define NSCAP_DONT_PROVIDE_NONCONST_OPEQ +#endif + +#ifndef NSCAP_DONT_PROVIDE_NONCONST_OPEQ template inline NSCAP_BOOL