Closed Bug 188141 Opened 22 years ago Closed 22 years ago

NS_CONST_CAST, NS_REINTERPRET_CAST, and NS_STATIC_CAST are not protected with parentheses properly

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: benjamin, Assigned: benjamin)

References

Details

Attachments

(1 file)

The macro definitions of NS_STATIC_CAST, NS_CONST_CAST, and NS_REINTERPRET_CAST
are not protected properly with parentheses.  This can lead to
order-of-operations errors, as a trivial example:

NS_REINTERPRET_CAST(nsISupports*,somevoidpointer)->AddRef();

will fail because -> is higher precedence than the cast operator.  Patch
forthcoming.
Oops, accidentally clicked wrong component.
Status: NEW → ASSIGNED
Component: XP Toolkit/Widgets: XUL → XPCOM
QA Contact: shrir → scc
Attachment #110920 - Flags: superreview?(scc)
Attachment #110920 - Flags: review?(dougt)
static_cast<T>() has the parentheses as part of the syntax -- see C++ section
5.2 clause 1.

The pattern that you say won't work is used all over the codebase (for example,
the first occurrence of NS_STATIC_CAST in nsBlockFrame.cpp), so I don't think
there are any compilers that do this wrong, either.
Oops, my bad.  I misunderstood a compiler error during casting.
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
Attachment #110920 - Flags: superreview?(scc)
Attachment #110920 - Flags: review?(dougt)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: