Wrong RTL instruction deleted

Florian Weimer fw@deneb.enyo.de
Mon Dec 27 13:56:00 GMT 2004


* Uros Bizjak:

> --cut here--
> #include <stdio.h>
>
> float foo ()
> {
>  unsigned int MASK = 0x80000000;
>  return (float &) MASK;
> }
>
> int main() {
>  printf ("%f\n", foo());
>  return 0;
> }
> --cut here--

This is covered by section 5.2.10 in the standard.  The return
statement is defined to be equivalent to (see 5.2.10(10)):

  return *reinterpret_cast<float *>(&MASK);

5.2.10(9) says that the result of this conversion is unspecified.

(IMHO, the missing warning about a type-punned pointer/reference is a
bug, though.)



More information about the Gcc mailing list