summaryrefslogtreecommitdiff
path: root/clang/test/Preprocessor/line-directive.c
blob: 28e93029a5ce4a38659aaadabeab8bd325053f37 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: ABC'
// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: DEF'

#line 'a'            // expected-error {{#line directive requires a positive integer argument}}
#line 0              // expected-error {{#line directive requires a positive integer argument}}
#line 00             // expected-error {{#line directive requires a positive integer argument}}
#line 2147483648     // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}}
#line 42             // ok
#line 42 'a'         // expected-error {{invalid filename for #line directive}}
#line 42 "foo/bar/baz.h"  // ok


// #line directives expand macros.
#define A 42 "foo"
#line A

# 42
# 42 "foo"
# 42 "foo" 2 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
# 42 "foo" 1 3  // enter
# 42 "foo" 2 3  // exit
# 42 "foo" 2 3 4 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
# 42 "foo" 3 4

# 'a'            // expected-error {{invalid preprocessing directive}}
# 42 'f'         // expected-error {{invalid filename for line marker directive}}
# 42 1 3         // expected-error {{invalid filename for line marker directive}}
# 42 "foo" 3 1   // expected-error {{invalid flag line marker directive}}
# 42 "foo" 42    // expected-error {{invalid flag line marker directive}}
# 42 "foo" 1 2   // expected-error {{invalid flag line marker directive}}


// These are checked by the RUN line.
#line 92 "blonk.c"
#error ABC  // expected-error {{#error ABC}}
#error DEF  // expected-error {{#error DEF}}


// Verify that linemarker diddling of the system header flag works.

# 192 "glomp.h" // not a system header.
typedef int x;  // expected-note {{previous definition is here}}
typedef int x;  // expected-warning {{redefinition of typedef 'x' is a C11 feature}}

# 192 "glomp.h" 3 // System header.
typedef int y;  // ok
typedef int y;  // ok

typedef int q;  // q is in system header.

#line 42 "blonk.h"  // doesn't change system headerness.

typedef int z;  // ok
typedef int z;  // ok

# 97     // doesn't change system headerness.

typedef int z1;  // ok
typedef int z1;  // ok

# 42 "blonk.h"  // DOES change system headerness.

typedef int w;  // expected-note {{previous definition is here}}
typedef int w;  // expected-warning {{redefinition of typedef 'w' is a C11 feature}}

typedef int q;  // original definition in system header, should not diagnose.

// This should not produce an "extra tokens at end of #line directive" warning,
// because #line is allowed to contain expanded tokens.
#define EMPTY()
#line 2 "foo.c" EMPTY( )
#line 2 "foo.c" NONEMPTY( )  // expected-warning{{extra tokens at end of #line directive}}

// PR3940
#line 0xf  // expected-error {{#line directive requires a simple digit sequence}}
#line 42U  // expected-error {{#line directive requires a simple digit sequence}}


// Line markers are digit strings interpreted as decimal numbers, this is
// 10, not 8.
#line 010  // expected-warning {{#line directive interprets number as decimal, not octal}}
extern int array[__LINE__ == 10 ? 1:-1];

/* PR3917 */
#line 41
extern char array2[\
_\
_LINE__ == 42 ? 1: -1];  /* line marker is location of first _ */