2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / cpp / defined.c
blob9a60bdd5d10620a3f903850af5af2cc033acda20
1 /* Copyright (C) 2000 Free Software Foundation, Inc. */
3 /* { dg-do preprocess } */
5 /* Tests behavior of the defined operator. */
7 /* Source: Neil Booth, 29 Oct 2000, Zack Weinberg 11 Dec 2000. */
9 #define defined /* { dg-error "defined" } */
11 /* No diagnostics, though you could argue there should be. */
12 #if defined defined
13 #error defined is defined!
14 #endif
16 #define is_Z_defined defined Z
18 #if defined Z
19 #error Z is not defined
20 #endif
22 /* The behavior of "defined" when it comes from a macro expansion is
23 now documented. */
24 #if is_Z_defined
25 #error Macro expanding into defined operator test 1
26 #endif
28 #define Z
30 #if !defined Z
31 #error Z is defined
32 #endif
34 #if !is_Z_defined
35 #error Macro expanding into defined operator test 2
36 #endif
38 #undef is_Z_defined
39 #undef Z
41 /* Do all the tests over again with the () form of defined. */
43 /* No diagnostics, though you could argue there should be. */
44 #if defined(defined)
45 #error defined is defined!
46 #endif
48 #define is_Z_defined defined ( Z )
50 #if defined(Z)
51 #error Z is not defined
52 #endif
54 /* The behavior of "defined" when it comes from a macro expansion is
55 now documented. */
56 #if is_Z_defined
57 #error Macro expanding into defined operator test 1
58 #endif
60 #define Z
62 #if !defined(Z)
63 #error Z is defined
64 #endif
66 #if !is_Z_defined
67 #error Macro expanding into defined operator test 2
68 #endif
70 /* Use of defined in different contexts. */
72 #define bad1 defined
73 #if !bad1 Z /* { dg-warning "may not be portable" } */
74 #error Z is defined
75 #endif
77 #if !bad1 (Z) /* { dg-warning "may not be portable" } */
78 #error Z is defined
79 #endif
81 #define bad2 defined (Z
82 #if !bad2) /* { dg-warning "may not be portable" } */
83 #error Z is defined
84 #endif