Closed
Bug 221316
Opened 22 years ago
Closed 22 years ago
nsCOMPtr operator== doesn't handle multiple inheritance correctly
Categories
(Core :: XPCOM, defect)
Core
XPCOM
Tracking
()
RESOLVED
FIXED
People
(Reporter: bryner, Assigned: bryner)
Details
Attachments
(1 file)
|
3.10 KB,
patch
|
dbaron
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
Here's an example:
class Foo : public nsIFoo, public nsIBar { ... };
void Foo::someFunction()
{
nsCOMPtr<nsIBar> ptr(this);
if (ptr == this) { ... }
}
The comparison will return false because nsCOMPtr casts both arguments to void*.
| Assignee | ||
Comment 1•22 years ago
|
||
| Assignee | ||
Updated•22 years ago
|
Attachment #132696 -
Flags: superreview?(darin)
Attachment #132696 -
Flags: review?(dbaron)
Comment on attachment 132696 [details] [diff] [review]
fix suggested by dbaron
Looks fine to me, except that for the last for I'd rather skip the
NS_CONST_CASTs and leave them un-cast.
Attachment #132696 -
Flags: review?(dbaron) → review+
Comment 3•22 years ago
|
||
Comment on attachment 132696 [details] [diff] [review]
fix suggested by dbaron
sr=darin with the same comment as dbaron. i think the code would be clearer
without the unnecessary NS_CONST_CAST expressions.
Attachment #132696 -
Flags: superreview?(darin) → superreview+
Actually, I take that back. Leave the NS_CONST_CASTs. They might help some
compilers when converting arguments.
Comment on attachment 132696 [details] [diff] [review]
fix suggested by dbaron
>@@ -1216,7 +1216,7 @@ inline
> NSCAP_BOOL
> operator==( U* lhs, const nsCOMPtr<T>& rhs )
> {
>- return NS_STATIC_CAST(void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
>+ return NS_CONST_CAST(U*, lhs) == NS_STATIC_CAST(const T*, rhs.get());
> }
>
And fix this one so it casts to |const U*|. :-)
Comment 6•22 years ago
|
||
This change breaks MipsPro (7.4.1) on IRIX:
cc-1042 CC: ERROR File = ../../../../dist/include/xpcom/nsCOMPtr.h, Line = 1211
The types of operands "const nsIHTMLCSSStyleSheet *" and
"const nsDerivedSafe<nsIStyleSheet> *" are incompatible.
return NS_STATIC_CAST(const T*, lhs.get()) == NS_CONST_CAST(const U*, rhs);
^
detected during instantiation of "NSCAP_BOOL operator==(const
nsCOMPtr<nsIHTMLCSSStyleSheet> &,
nsDerivedSafe<nsIStyleSheet> *)" at line 782 of
"/build2/tinderbox/mozilla/build/IRIX_6.5_Depend/mozilla/co
ntent/xml/document/src/nsXMLDocument.cpp"
cc-1042 CC: ERROR File = ../../../../dist/include/xpcom/nsCOMPtr.h, Line = 1211
The types of operands "const nsIHTMLStyleSheet *" and
"const nsDerivedSafe<nsIStyleSheet> *" are incompatible.
return NS_STATIC_CAST(const T*, lhs.get()) == NS_CONST_CAST(const U*, rhs);
^
detected during instantiation of "NSCAP_BOOL operator==(const
nsCOMPtr<nsIHTMLStyleSheet> &,
nsDerivedSafe<nsIStyleSheet> *)" at line 835 of
"/build2/tinderbox/mozilla/build/IRIX_6.5_Depend/mozilla/co
ntent/xml/document/src/nsXMLDocument.cpp"
That's been fixed. Look at tinderbox. And see also bug 221525.
Comment 8•22 years ago
|
||
Great, thanks :-)
| Assignee | ||
Comment 9•22 years ago
|
||
checked in, and I think we got the bustage under control.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•