bug 348748 make NS_*_CAST always use C++-style casts (in preparation for

removing the macros altogether)
r=bsmedberg sr=dbaron
This commit is contained in:
cbiesinger%web.de 2006-09-04 23:04:57 +00:00
Родитель 08ba285a62
Коммит 33e35afd71
1 изменённых файлов: 0 добавлений и 47 удалений

Просмотреть файл

@ -423,14 +423,6 @@ typedef PRUint32 nsrefcnt;
#define NS_SPECIALIZE_TEMPLATE
#endif
/* unix and beos now determine this automatically */
#if ! defined XP_UNIX && ! defined XP_BEOS && !defined(XP_OS2)
#ifndef HAVE_CPP_NEW_CASTS
#define HAVE_CPP_NEW_CASTS 1 /* we'll be optimistic. */
#endif
#endif
#if defined(HAVE_CPP_NEW_CASTS)
#define NS_STATIC_CAST(__type, __ptr) static_cast< __type >(__ptr)
#define NS_CONST_CAST(__type, __ptr) const_cast< __type >(__ptr)
@ -438,45 +430,6 @@ typedef PRUint32 nsrefcnt;
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) reinterpret_cast< __type >(__obj)
#define NS_REINTERPRET_CAST(__type, __expr) reinterpret_cast< __type >(__expr)
#else
#define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
#define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) ((__type)((void*)(__ptr)))
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) ((__type)(__obj))
/* Note: the following is only appropriate for pointers. */
#define NS_REINTERPRET_CAST(__type, __expr) NS_REINTERPRET_POINTER_CAST(__type, __expr)
/*
Why cast to a |void*| first? Well, when old-style casting from
a pointer to a base to a pointer to a derived class, the cast will be
ambiguous if the source pointer type appears multiple times in the
destination, e.g.,
class Base {};
class Derived : public Base, public Base {};
void foo( Base* b )
{
((Derived*)b)->some_derived_member ... // Error: Ambiguous, expand from which |Base|?
}
an old-style cast (like |static_cast|) will change the pointer, but
here, doesn't know how. The cast to |void*| prevents it from thinking
it needs to expand the original pointer.
The cost is, |NS_REINTERPRET_CAST| is no longer appropriate for non-pointer
conversions. Also, mis-applying |NS_REINTERPRET_CAST| to cast |this| to something
will still expand the pointer to the outer object in standards complying compilers.
*/
/*
No sense in making an NS_DYNAMIC_CAST() macro: you can't duplicate
the semantics. So if you want to dynamic_cast, then just use it
"straight", no macro.
*/
#endif
/*
* Use these macros to do 64bit safe pointer conversions.
*/