bugzilla.mozilla.org has resumed normal operation. Attachments prior to 2014 will be unavailable for a few days. This is tracked in Bug 1475801.
Please report any other irregularities here.

Gcc-3.4.0 compiler warnings

RESOLVED WORKSFORME

Status

()

Core
JavaScript Engine
RESOLVED WORKSFORME
14 years ago
7 years ago

People

(Reporter: tenthumbs, Unassigned)

Tracking

(Blocks: 1 bug)

Trunk
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [build_warning])

(Reporter)

Description

14 years ago
I have no idea how important this really is but gcc has these warnings.

jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object  
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:419: warning: ISO C forbids conversion of function pointer to object 
   pointer type
jsdbgapi.c:423: warning: ISO C forbids conversion of object pointer to function 
   pointer type
jsinterp.c:4151: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4151: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4264: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4264: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4331: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4331: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4429: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsinterp.c:4434: warning: ISO C forbids conversion of object pointer to function
   pointer type
jsobj.c:1429: warning: ISO C forbids conversion of object pointer to function 
  pointer type
jsobj.c:1460: warning: ISO C forbids conversion of object pointer to function 
  pointer type

Comment 1

14 years ago
It's legal to convert a function pointer to a suitably large integral or object
pointer type so long as you convert the pointer back to a function pointer of
the correct type before using it.  I thought there was a check that function
pointers fit but I cannot find it at the moment.

Comment 2

14 years ago
I'm told that while that's true for C++, it's a common extension but not
required to be supported in ISO C.  *sigh*
Yeah, ISO C blew it.  Any C99 hope?

/be

Comment 4

14 years ago
Doesn't look like it.  From the C99 supplementary rationale v5.10 section
6.3.2.3 under "Consequences of the treatment of pointer types":

Even with an explicit cast, it is invalid to convert a function pointer to an
object pointer or a pointer to void, or vice versa.

Comment 5

14 years ago
Brendan: those compiler warnings are technically correct.
(Note that it is legal to cast a pointer to a function
to a pointer to another function type.)

By the way, this is why we added a new NSPR function
PR_FindFunctionSymbol that returns a function pointer
because PR_FindSymbol returns a data pointer (void*).

http://lxr.mozilla.org/nspr/source/nsprpub/pr/include/prlink.h#196
This is some old crack-baby concession to Crays or Cybers, or some other dead
architecture that had goofy 48-bit segmented code pointers but 32-bit data, or
something even weirder.  If it mattered, C++ would match it.  I intend to ignore
it ;-).

/be

Comment 7

14 years ago
Brendan: are you sure C++ allows this?
Wan-Teh: I'm parroting comment #2 on C++ not being as lame as C.  Cc'ing dbaron
in case he knows for sure.

/be

Comment 9

14 years ago
Digging into this further, it appears that standard C++ has gone from allowing
explicit conversions, to allowing explicit and implicit conversions, to
disallowing all conversions.  Which would put the latest version in the same
boat as ISO C.  I do note that it's proposed to further change to allow explicit
conversions with implementation defined behavior.

Through all of this, it appears legal to cast a function pointer to a suitably
large integral type to an object pointer and back again.

I hope dbaron can shed some light on this.

And for wtc, isn't it required that the two function types have the same linkage
type for the cast to be valid?
-> default qa
QA Contact: pschwartau → general

Updated

7 years ago
Whiteboard: [build_warning]

Updated

7 years ago
Blocks: 187528

Comment 11

7 years ago
jsdbgapi.c file might have been renamed to jsdbgapi.cpp which have removed the warnings. There is no warning reported by this bug in windows, linux and osx builds (nightly builds). 
Hence closing the bug.
Status: NEW → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.