Tests by Zack Weinberg <zackw@stanford.edu>.
[official-gcc.git] / gcc / testsuite / gcc.dg / cpp / defined_trad.c
blob666fd712f5adf71c4a1a1936e57cfb54fc6f8184
1 /* Copyright (C) 2000 Free Software Foundation, Inc. */
3 /* { dg-do preprocess } */
4 /* { dg-options "-traditional" } */
6 /* Tests tradcpp0 with defined. The defined operator in traditional C
7 works just the same as the defined operator in Standard C. */
9 /* Source: Zack Weinberg, glibc, Neil Booth 11 Dec 2000. */
11 #if defined REGPARMS
12 #error REGPARMS should not be defined
13 #endif
15 #define REGPARMS 1
16 #if !defined REGPARMS
17 #error REGPARMS should be defined
18 #endif
20 #define defined /* { dg-error "defined" } */
22 /* No diagnostics, though you could argue there should be. */
23 #if defined defined
24 #error defined is defined!
25 #endif
27 #define is_Z_defined defined Z
29 #if defined Z
30 #error Z is not defined
31 #endif
33 /* The behaviour of "defined" when it comes from a macro expansion is
34 now documented. */
35 #if is_Z_defined
36 #error Macro expanding into defined operator test 1
37 #endif
39 #define Z
41 #if !defined Z
42 #error Z is defined
43 #endif
45 #if !is_Z_defined
46 #error Macro expanding into defined operator test 2
47 #endif
49 #undef is_Z_defined
50 #undef Z
52 /* Do all the tests over again with the () form of defined. */
54 /* No diagnostics, though you could argue there should be. */
55 #if defined(defined)
56 #error defined is defined!
57 #endif
59 #define is_Z_defined defined ( Z )
61 #if defined(Z)
62 #error Z is not defined
63 #endif
65 /* The behaviour of "defined" when it comes from a macro expansion is
66 now documented. */
67 #if is_Z_defined
68 #error Macro expanding into defined operator test 1
69 #endif
71 #define Z
73 #if !defined(Z)
74 #error Z is defined
75 #endif
77 #if !is_Z_defined
78 #error Macro expanding into defined operator test 2
79 #endif