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