2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.bugs / 900227_01.C
blob78450df68413fcb955bc3b07f402495757a860de
1 // { dg-do assemble  }
2 // { dg-options "" }
3 // g++ 1.37.1 bug 900227_01
5 // g++ allows pointer type values to be converted to integral types which are
6 // not actually large enough to hold the converted values.
8 // Section 3.3.4 of the ANSI C standard says:
10 //      A pointer may be converted to an integral type.  The size of the
11 //      integer required and the results are implementation defined.  If
12 //      the space provided is not long enough, the behavior is undefined.
14 // I believe that the only proper thing to do in such cases is to generate
15 // errors.  After all, if the converted value gets truncated, it is not
16 // likely to be useful after that.
18 // Furthermore, as the following example demonstrates, allowing pointers
19 // to be converted to integral types which are not of sufficient size to
20 // completely hold the converted values may cause additional troubles.
22 // I tried the following code on 5 different machines and it failed on
23 // all five (unless I also use the GNU assembler and the GNU linker).  Three
24 // of the five (Sun3, Sun4, and Symmetry) got link-time errors about byte
25 // offset overflows.  The other two (368/SystemV and AViiON) got assembly
26 // time errors about relocatable names used in "constant" expressions.
28 // keywords: casts, pointer types, integral types
30 // Update 2/10/95: The compiler will now compute these expressions at
31 // runtime.  I think this is in the spirit of the GNU compilers (jason).
34 int main ();
36 short s = (short) &main;        // { dg-warning "" "" { xfail h8*-*-* xstormy16-*-* } } small integer 
37 char c = (char) &main;          // { dg-warning "" } small integer
39 int main () { return 0; }