Closed Bug 49640 Opened 24 years ago Closed 15 years ago

C cast used on C++ object

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: bruce, Unassigned)

References

(Blocks 1 open bug, )

Details

nsIFile.idl has this line in it:
*result = (nsIFile*)dir.get();

The HP compiler warns about this, but I was under the impression that we 
shouldn't be using C-style casts on any C++ objects like that.

For reference, the HP warning is:
Warning 749: "../../dist/include/nsIFile.h", line 761 # The cast from 
'nsDerivedSafe<nsISupports> *' to 'nsIFile *' is performed as a 
'reinterpret_cast'. This operation is non-portable and potentially unsafe.
        *result = (nsIFile*)dir.get();
Doing a simple search, for example, on ".get()" would seem ti indicate that this 
type of cast is being done all over the place.  Are the others somehow not 
reported as warnings by the HP compiler?  What would you suggest to replace this 
reinterpret cast?
Some are ... I've reported most of the non-mail/news instances of this warning. 
If nothing else, it'd be nice to see the actual C++ cast via NS_REINTERPRET_CAST
used rather than the C-style one.

One other thing that I'm not clear on is what the order of operations is in the
case of this expression.  Is it doing:  ((nsIFile*)dir).get(), or is it doing
(nsIFile*)(dir.get()) ?
I was just determining the priority so I could triage it properly.

Dots bind much tighter than casting.  You always have to use extra parents to 
cast before using a dot.

Are you saying the HP warning goes a way when we use REINTERPRET_CAST?  If so, 
I'd hope we could make a single bug and get someone to go through all the source 
eliminating the older form.  I am making this future.
Status: NEW → ASSIGNED
Target Milestone: --- → Future
I already went through the HP build logs and filed almost all of the appropriate
bugs. (I left out anything involving structs rather than real C++ classes.)

If I submit a patch for this trivial fix to nsIFile.idl, can you review it, so
that I can get it approved by waterson?  (This particular warning is the single
most common instance of it in the source, with the 2nd most common being some
xpconnect ones that jband is already on.)
Edward: Welcome to xpcom!
Status: ASSIGNED → NEW
QA Contact: leger → rayw
Target Milestone: Future → mozilla1.0
Once again... attempting to reassign from Ray to Edward.
Assignee: rayw → kandrot
Submit the patch, and I'll review it (rayw is no longer associated with XPCOM).
Status: NEW → ASSIGNED
QA Contact: rayw → scc
Assignee: kandrot → dougt
Status: ASSIGNED → NEW
Target Milestone: mozilla1.0 → ---
reassign all kandrot xpcom bug.
Keywords: helpwanted
Target Milestone: --- → Future
Assignee: dougt → nobody
QA Contact: scc → xpcom
Don't care about C casts enough to keep this bug open.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → INCOMPLETE
Priority: P3 → --
Target Milestone: Future → ---
You need to log in before you can comment on or make changes to this bug.