diff --git a/xpcom/public/COM_auto_ptr.h b/xpcom/public/COM_auto_ptr.h index 4ff90ee6a0f4..7dfa0ac7b541 100644 --- a/xpcom/public/COM_auto_ptr.h +++ b/xpcom/public/COM_auto_ptr.h @@ -35,7 +35,7 @@ #if defined(NOT_PRODUCTION_CODE) && defined(USE_EXPERIMENTAL_SMART_POINTERS) -#include +#include /* USER MANUAL @@ -156,6 +156,10 @@ /* Set up some #defines to turn off a couple of troublesome C++ features. Interestingly, none of the compilers barf on template stuff. + + Ideally, we would want declarations like these in a configuration file + that that everybody would get. Deciding exactly how to do that should + be part of the process of moving from experimental to production. */ #if defined(__GNUG__) && (__GNUC_MINOR__ <= 90) && !defined(SOLARIS) @@ -166,10 +170,26 @@ #define NO_EXPLICIT #endif +#if defined(IRIX) + #define NO_MEMBER_USING_DECLARATIONS + #define NO_EXPLICIT + #define NO_NEW_CASTS +#endif + + + #ifdef NO_EXPLICIT #define explicit #endif +#ifndef NO_NEW_CASTS + #define STATIC_CAST(T,x) static_cast(x) + #define REINTERPRET_CAST(T,x) reinterpret_cast(x) +#else + #define STATIC_CAST(T,x) ((T)(x)) + #define REINTERPRET_CAST(T,x) ((T)(x)) +#endif + template class derived_safe : public T @@ -186,8 +206,8 @@ class derived_safe : public T using T::AddRef; using T::Release; #else - unsigned long AddRef() { } - unsigned long Release() { } + unsigned long AddRef(); + unsigned long Release(); #endif }; @@ -339,7 +359,7 @@ class COM_auto_ptr get() const // returns a |derived_safe*| to deny clients the use of |AddRef| and |Release| { - return reinterpret_cast*>(ptr_); + return REINTERPRET_CAST(derived_safe*, ptr_); } void @@ -399,7 +419,7 @@ class func_AddRefs_t operator void**() { - return reinterpret_cast(&ptr_); + return REINTERPRET_CAST(void**, &ptr_); } operator T**() @@ -446,7 +466,7 @@ class func_doesnt_AddRef_t operator void**() { - return reinterpret_cast(&ptr_); + return REINTERPRET_CAST(void**, &ptr_); } operator T**() diff --git a/xpcom/tests/test_COM_auto_ptr.cpp b/xpcom/tests/test_COM_auto_ptr.cpp index 476884d778a5..1cbb92ce0ba8 100644 --- a/xpcom/tests/test_COM_auto_ptr.cpp +++ b/xpcom/tests/test_COM_auto_ptr.cpp @@ -94,20 +94,20 @@ IFoo::IFoo() : refcount_(0) { ++total_constructions_; - cout << " new IFoo@" << static_cast(this) << " [#" << total_constructions_ << "]" << endl; + cout << " new IFoo@" << STATIC_CAST(void*, this) << " [#" << total_constructions_ << "]" << endl; } IFoo::~IFoo() { ++total_destructions_; - cout << "IFoo@" << static_cast(this) << "::~IFoo()" << " [#" << total_destructions_ << "]" << endl; + cout << "IFoo@" << STATIC_CAST(void*, this) << "::~IFoo()" << " [#" << total_destructions_ << "]" << endl; } unsigned long IFoo::AddRef() { ++refcount_; - cout << "IFoo@" << static_cast(this) << "::AddRef(), refcount --> " << refcount_ << endl; + cout << "IFoo@" << STATIC_CAST(void*, this) << "::AddRef(), refcount --> " << refcount_ << endl; return refcount_; } @@ -119,16 +119,16 @@ IFoo::Release() cout << ">>"; --refcount_; - cout << "IFoo@" << static_cast(this) << "::Release(), refcount --> " << refcount_ << endl; + cout << "IFoo@" << STATIC_CAST(void*, this) << "::Release(), refcount --> " << refcount_ << endl; if ( !refcount_ ) { - cout << " delete IFoo@" << static_cast(this) << endl; + cout << " delete IFoo@" << STATIC_CAST(void*, this) << endl; delete this; } if ( wrap_message ) - cout << "<(this) << "::Release()" << endl; + cout << "<>CreateIFoo() --> "; IFoo* foop = new IFoo; - cout << "IFoo@" << static_cast(foop) << endl; + cout << "IFoo@" << STATIC_CAST(void*, foop) << endl; foop->AddRef(); *result = foop; @@ -180,12 +180,12 @@ class IBar : public IFoo IBar::IBar() { - cout << " new IBar@" << static_cast(this) << endl; + cout << " new IBar@" << STATIC_CAST(void*, this) << endl; } IBar::~IBar() { - cout << "IBar@" << static_cast(this) << "::~IBar()" << endl; + cout << "IBar@" << STATIC_CAST(void*, this) << "::~IBar()" << endl; } @@ -196,7 +196,7 @@ CreateIBar( void** result ) { cout << ">>CreateIBar() --> "; IBar* barp = new IBar; - cout << "IBar@" << static_cast(barp) << endl; + cout << "IBar@" << STATIC_CAST(void*, barp) << endl; barp->AddRef(); *result = barp; @@ -239,10 +239,10 @@ main() //foop->Release(); cout << endl << "### Test 3: can you |AddRef| if you must?" << endl; - static_cast(foop)->AddRef(); + STATIC_CAST(IFoo*, foop)->AddRef(); cout << endl << "### Test 4: can you |Release| if you must?" << endl; - static_cast(foop)->Release(); + STATIC_CAST(IFoo*, foop)->Release(); cout << endl << "### Test 5: will a |COM_auto_ptr| |Release| when it goes out of scope?" << endl; }