Open Bug 646812 Opened 13 years ago Updated 2 years ago

nsTraceRefcnt.h should use NS_ISUPPORTS_CAST to work around ambiguous cast path

Categories

(Core :: XPCOM, defect)

defect

Tracking

()

People

(Reporter: hsivonen, Unassigned)

Details

Ehsan says in bug 482909 comment 15:
> (In reply to comment #14)
> > In file included from ../../../dist/include/nsComponentManagerUtils.h:46,
> >                  from ../../../dist/include/nsIComponentManager.h:164,
> >                  from
> > /opt/Projects/mozilla-html5/toolkit/components/feeds/nsScriptableUnescapeHTML.cpp:38:
> > ../../../dist/include/nsCOMPtr.h: In destructor ‘nsCOMPtr<T>::~nsCOMPtr() [with
> > T = nsIPrincipal]’:
> > ../../../dist/include/nsTreeSanitizer.h:44:   instantiated from here
> > ../../../dist/include/nsCOMPtr.h:531: error: invalid static_cast from type
> > ‘nsIPrincipal*’ to type ‘nsISupports*’
> > ../../../dist/include/nsCOMPtr.h:533: error: invalid use of incomplete type
> > ‘struct nsIPrincipal’
> > ../../../dist/include/nsNodeInfoManager.h:53: error: forward declaration of
> > ‘struct nsIPrincipal’
> > make[6]: *** [nsScriptableUnescapeHTML.o] Error 1
> 
> Hmm, that's coming from
> <http://mxr.mozilla.org/mozilla-central/source/xpcom/glue/nsTraceRefcnt.h#80> I
> bet.  I think that code should use NS_ISUPPORTS_CAST, which works around the
> ambiguous possible cast path.  Can you please file a bug about that?
The error here is not an ambiguous cast, but a cast from an incomplete type. I don't think NS_ISUPPORTS_CAST would help at all. #including "nsIPrincipal.h" would, though.
(In reply to comment #1)
> The error here is not an ambiguous cast, but a cast from an incomplete type. I
> don't think NS_ISUPPORTS_CAST would help at all. #including "nsIPrincipal.h"
> would, though.

Yes, but I think the static_cast that we use there right now can be a problem in the case of an ambiguous cast.  Do you think this is something that we should fix?
Severity: minor → S4
You need to log in before you can comment on or make changes to this bug.