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

RESOLVED INVALID

Status

()

Core
XPCOM
RESOLVED INVALID
15 years ago
15 years ago

People

(Reporter: Benjamin Smedberg, Assigned: Benjamin Smedberg)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

15 years ago
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.
(Assignee)

Comment 1

15 years ago
Created attachment 110920 [details] [diff] [review]
patch to protect cast macros with parentheses
(Assignee)

Comment 2

15 years ago
Oops, accidentally clicked wrong component.
Status: NEW → ASSIGNED
Component: XP Toolkit/Widgets: XUL → XPCOM
QA Contact: shrir → scc
(Assignee)

Updated

15 years ago
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.
(Assignee)

Comment 4

15 years ago
Oops, my bad.  I misunderstood a compiler error during casting.
Status: ASSIGNED → RESOLVED
Last Resolved: 15 years ago
Resolution: --- → INVALID
(Assignee)

Updated

15 years ago
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.