OSDN Git Service

update
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.bugs / 900227_01.C
1 // g++ 1.37.1 bug 900227_01
2
3 // g++ allows pointer type values to be converted to integral types which are
4 // not actually large enough to hold the converted values.
5
6 // Section 3.3.4 of the ANSI C standard says:
7
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.
11
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.
15
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.
19
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.
25
26 // keywords: casts, pointer types, integral types
27
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).
30
31 // Special g++ Options:
32
33 #include <limits.h>
34
35 int main ();
36
37 #if INT_MAX > 32767
38 short s = (short) &main;        // WARNING - small integer
39 #endif
40 char c = (char) &main;          // WARNING - small integer
41
42 int main () { return 0; }