2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / cpp / spacing1.c
blob2d70f869d2192cf7abfc80927e2c019baee132b3
1 /* Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. */
3 /* { dg-do preprocess } */
5 /* This tests correct spacing of macro expansion output, as well as
6 the line it falls on. This is quite subtle; it involves newlines
7 within macro arguments becoming spaces, but not if it turns out to
8 not be a macro invocation. Also, multiple macro invocations spread
9 across many lines.
11 Neil Booth, 1 Dec 2000, 23 Sep 2001. */
13 /* The actual location of the expansion of a multi-line macro
14 invocation is not defined: we might consider them to be in the same
15 line as the initial token of the invocation, or as the final token
16 of the invocation, or even anything in between. We choose to make
17 it the initial token, such that everything that is in a logical
18 line ends up in a single line after preprocessing.
20 Alexandre Oliva, Sept 13, 2003. */
22 #define str(x) #x
23 #define f(x) x
24 #define glue(x, y) x ## y
25 #define EMPTY
26 /* These are based on PR 4492, we mustn't lose padding tokens when
27 scanning ahead for a '(' and failing to find it. */
28 #define A(x) B x
29 #define B(x)
30 #define C A
31 #define D() A
33 /* The correct output is shown here. Note the spaces, and the way
34 everything after the invocation of f appears on the same line.
36 44 ;
37 B Q B Q A Q A:
39 bar
41 bad
42 g "1 2" bam baz
46 glue (EMPTY 4, 4) EMPTY;
47 A(Q) C(Q) D()Q D():
49 bar
51 bad
52 f (g) str
56 ) f
57 (bam) baz
59 /* { dg-final { scan-file spacing1.i " 44 ;" } }
60 { dg-final { scan-file spacing1.i "B Q B Q A Q A:" } }
61 { dg-final { scan-file-not spacing1.i "f\[^\n\]*bar" } }
62 { dg-final { scan-file spacing1.i "(^|\n)bar" } }
63 { dg-final { scan-file spacing1.i "(^|\n)A($|\n)" } }
64 { dg-final { scan-file spacing1.i "(^|\n)bad($|\n)" } }
65 { dg-final { scan-file spacing1.i "g \"1 2\" bam baz" } } */