OSDN Git Service

PR preprocessor/30805:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / cpp / defined.c
1 /* Copyright (C) 2000 Free Software Foundation, Inc.  */
2
3 /* { dg-do preprocess } */
4
5 /* Tests behavior of the defined operator.  */
6
7 /*  Source: Neil Booth, 29 Oct 2000, Zack Weinberg 11 Dec 2000.  */
8
9 #define defined                 /* { dg-error "defined" } */
10
11 /* No diagnostics, though you could argue there should be.  */
12 #if defined defined
13 #error defined is defined!
14 #endif
15
16 #define is_Z_defined defined Z
17
18 #if defined Z
19 #error Z is not defined
20 #endif
21
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
27
28 #define Z
29
30 #if !defined Z
31 #error Z is defined
32 #endif
33
34 #if !is_Z_defined
35 #error Macro expanding into defined operator test 2
36 #endif
37
38 #undef is_Z_defined
39 #undef Z
40
41 /* Do all the tests over again with the () form of defined.  */
42
43 /* No diagnostics, though you could argue there should be.  */
44 #if defined(defined)
45 #error defined is defined!
46 #endif
47
48 #define is_Z_defined defined ( Z )
49
50 #if defined(Z)
51 #error Z is not defined
52 #endif
53
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
59
60 #define Z
61
62 #if !defined(Z)
63 #error Z is defined
64 #endif
65
66 #if !is_Z_defined
67 #error Macro expanding into defined operator test 2
68 #endif
69
70 /* Use of defined in different contexts.  */
71
72 #define bad1 defined
73 #if !bad1 Z                     /* { dg-warning "may not be portable" } */
74 #error Z is defined
75 #endif 
76
77 #if !bad1 (Z)                   /* { dg-warning "may not be portable" } */
78 #error Z is defined
79 #endif 
80
81 #define bad2 defined (Z
82 #if !bad2)                      /* { dg-warning "may not be portable" } */
83 #error Z is defined
84 #endif 
85