blob: 04c69a6791adcc19bf3fe29e4dbef647266dfce8 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify -pedantic %s &&
2// RUN: clang-cc -E %s 2>&1 | grep 'blonk.c:92:2: error: #error ABC' &&
3// RUN: clang-cc -E %s 2>&1 | grep 'blonk.c:93:2: error: #error DEF'
Chris Lattner359cc442009-01-26 05:29:08 +00004
5#line 'a' // expected-error {{#line directive requires a positive integer argument}}
6#line 0 // expected-error {{#line directive requires a positive integer argument}}
Chris Lattnerdc8c90d2009-04-18 18:35:15 +00007#line 00 // expected-error {{#line directive requires a positive integer argument}}
Chris Lattner359cc442009-01-26 05:29:08 +00008#line 2147483648 // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}}
9#line 42 // ok
Chris Lattner137b6a62009-02-04 06:25:26 +000010#line 42 'a' // expected-error {{invalid filename for #line directive}}
Chris Lattner359cc442009-01-26 05:29:08 +000011#line 42 "foo/bar/baz.h" // ok
12
13
Chris Lattner8e60a292009-01-26 05:44:13 +000014// #line directives expand macros.
15#define A 42 "foo"
16#line A
17
Chris Lattner478a18e2009-01-26 06:19:46 +000018# 42
19# 42 "foo"
Chris Lattner137b6a62009-02-04 06:25:26 +000020# 42 "foo" 2 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
21# 42 "foo" 1 3 // enter
22# 42 "foo" 2 3 // exit
23# 42 "foo" 2 3 4 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
Chris Lattner478a18e2009-01-26 06:19:46 +000024# 42 "foo" 3 4
25
26# 'a' // expected-error {{invalid preprocessing directive}}
27# 42 'f' // expected-error {{invalid filename for line marker directive}}
28# 42 1 3 // expected-error {{invalid filename for line marker directive}}
29# 42 "foo" 3 1 // expected-error {{invalid flag line marker directive}}
30# 42 "foo" 42 // expected-error {{invalid flag line marker directive}}
31# 42 "foo" 1 2 // expected-error {{invalid flag line marker directive}}
Chris Lattner953b4b02009-02-04 02:17:09 +000032
33
34// These are checked by the RUN line.
35#line 92 "blonk.c"
36#error ABC // expected-error {{#error ABC}}
37#error DEF // expected-error {{#error DEF}}
38
Chris Lattner6b306672009-02-04 05:33:01 +000039
40// Verify that linemarker diddling of the system header flag works.
41
42# 192 "glomp.h" // not a system header.
43typedef int x; // expected-note {{previous definition is here}}
Chris Lattner32b06752009-04-17 22:04:20 +000044typedef int x; // expected-error {{redefinition of typedef 'x' is invalid in C}}
Chris Lattner6b306672009-02-04 05:33:01 +000045
46# 192 "glomp.h" 3 // System header.
47typedef int y; // ok
48typedef int y; // ok
49
50#line 42 "blonk.h" // doesn't change system headerness.
51
52typedef int z; // ok
53typedef int z; // ok
54
Chris Lattnerbd162092009-02-04 05:36:14 +000055# 97 // doesn't change system headerness.
56
57typedef int z1; // ok
58typedef int z1; // ok
59
Chris Lattner6b306672009-02-04 05:33:01 +000060# 42 "blonk.h" // DOES change system headerness.
61
62typedef int w; // expected-note {{previous definition is here}}
Chris Lattner32b06752009-04-17 22:04:20 +000063typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C}}
Chris Lattnerab82f412009-04-17 23:30:53 +000064
65
66// This should not produce an "extra tokens at end of #line directive" warning,
67// because #line is allowed to contain expanded tokens.
68#define EMPTY()
69#line 2 "foo.c" EMPTY( )
70#line 2 "foo.c" NONEMPTY( ) // expected-warning{{extra tokens at end of #line directive}}
71
Chris Lattner58e91d52009-04-17 23:37:49 +000072// PR3940
Chris Lattnerdc8c90d2009-04-18 18:35:15 +000073#line 0xf // expected-error {{#line directive requires a simple digit sequence}}
74#line 42U // expected-error {{#line directive requires a simple digit sequence}}
Chris Lattnerbc816822009-04-18 06:38:24 +000075
76
Chris Lattnerdc8c90d2009-04-18 18:35:15 +000077// Line markers are digit strings interpreted as decimal numbers, this is
78// 10, not 8.
79#line 010 // expected-warning {{#line directive interprets number as decimal, not octal}}
80extern int array[__LINE__ == 10 ? 1:-1];
81