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