Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s |
| 2 | // RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: #error ABC' |
| 3 | // RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: #error DEF' |
Chris Lattner | 359cc44 | 2009-01-26 05:29:08 +0000 | [diff] [blame] | 4 | |
| 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 Lattner | dc8c90d | 2009-04-18 18:35:15 +0000 | [diff] [blame] | 7 | #line 00 // expected-error {{#line directive requires a positive integer argument}} |
Chris Lattner | 359cc44 | 2009-01-26 05:29:08 +0000 | [diff] [blame] | 8 | #line 2147483648 // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}} |
| 9 | #line 42 // ok |
Chris Lattner | 137b6a6 | 2009-02-04 06:25:26 +0000 | [diff] [blame] | 10 | #line 42 'a' // expected-error {{invalid filename for #line directive}} |
Chris Lattner | 359cc44 | 2009-01-26 05:29:08 +0000 | [diff] [blame] | 11 | #line 42 "foo/bar/baz.h" // ok |
| 12 | |
| 13 | |
Chris Lattner | 8e60a29 | 2009-01-26 05:44:13 +0000 | [diff] [blame] | 14 | // #line directives expand macros. |
| 15 | #define A 42 "foo" |
| 16 | #line A |
| 17 | |
Chris Lattner | 478a18e | 2009-01-26 06:19:46 +0000 | [diff] [blame] | 18 | # 42 |
| 19 | # 42 "foo" |
Chris Lattner | 137b6a6 | 2009-02-04 06:25:26 +0000 | [diff] [blame] | 20 | # 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 Lattner | 478a18e | 2009-01-26 06:19:46 +0000 | [diff] [blame] | 24 | # 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 Lattner | 953b4b0 | 2009-02-04 02:17:09 +0000 | [diff] [blame] | 32 | |
| 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 Lattner | 6b30667 | 2009-02-04 05:33:01 +0000 | [diff] [blame] | 39 | |
| 40 | // Verify that linemarker diddling of the system header flag works. |
| 41 | |
| 42 | # 192 "glomp.h" // not a system header. |
| 43 | typedef int x; // expected-note {{previous definition is here}} |
Chris Lattner | d0359af | 2009-04-27 01:46:12 +0000 | [diff] [blame] | 44 | typedef int x; // expected-error {{redefinition of typedef 'x' is invalid in C}} |
Chris Lattner | 6b30667 | 2009-02-04 05:33:01 +0000 | [diff] [blame] | 45 | |
| 46 | # 192 "glomp.h" 3 // System header. |
| 47 | typedef int y; // ok |
| 48 | typedef int y; // ok |
| 49 | |
Chris Lattner | d0359af | 2009-04-27 01:46:12 +0000 | [diff] [blame] | 50 | typedef int q; // q is in system header. |
| 51 | |
Chris Lattner | 6b30667 | 2009-02-04 05:33:01 +0000 | [diff] [blame] | 52 | #line 42 "blonk.h" // doesn't change system headerness. |
| 53 | |
| 54 | typedef int z; // ok |
| 55 | typedef int z; // ok |
| 56 | |
Chris Lattner | bd16209 | 2009-02-04 05:36:14 +0000 | [diff] [blame] | 57 | # 97 // doesn't change system headerness. |
| 58 | |
| 59 | typedef int z1; // ok |
| 60 | typedef int z1; // ok |
| 61 | |
Chris Lattner | 6b30667 | 2009-02-04 05:33:01 +0000 | [diff] [blame] | 62 | # 42 "blonk.h" // DOES change system headerness. |
| 63 | |
| 64 | typedef int w; // expected-note {{previous definition is here}} |
Chris Lattner | d0359af | 2009-04-27 01:46:12 +0000 | [diff] [blame] | 65 | typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C}} |
Chris Lattner | ab82f41 | 2009-04-17 23:30:53 +0000 | [diff] [blame] | 66 | |
Chris Lattner | d0359af | 2009-04-27 01:46:12 +0000 | [diff] [blame] | 67 | typedef int q; // original definition in system header, should not diagnose. |
Chris Lattner | ab82f41 | 2009-04-17 23:30:53 +0000 | [diff] [blame] | 68 | |
| 69 | // This should not produce an "extra tokens at end of #line directive" warning, |
| 70 | // because #line is allowed to contain expanded tokens. |
| 71 | #define EMPTY() |
| 72 | #line 2 "foo.c" EMPTY( ) |
| 73 | #line 2 "foo.c" NONEMPTY( ) // expected-warning{{extra tokens at end of #line directive}} |
| 74 | |
Chris Lattner | 58e91d5 | 2009-04-17 23:37:49 +0000 | [diff] [blame] | 75 | // PR3940 |
Chris Lattner | dc8c90d | 2009-04-18 18:35:15 +0000 | [diff] [blame] | 76 | #line 0xf // expected-error {{#line directive requires a simple digit sequence}} |
| 77 | #line 42U // expected-error {{#line directive requires a simple digit sequence}} |
Chris Lattner | bc81682 | 2009-04-18 06:38:24 +0000 | [diff] [blame] | 78 | |
| 79 | |
Chris Lattner | dc8c90d | 2009-04-18 18:35:15 +0000 | [diff] [blame] | 80 | // Line markers are digit strings interpreted as decimal numbers, this is |
| 81 | // 10, not 8. |
| 82 | #line 010 // expected-warning {{#line directive interprets number as decimal, not octal}} |
| 83 | extern int array[__LINE__ == 10 ? 1:-1]; |
| 84 | |
Chris Lattner | dff070f | 2009-04-18 22:29:33 +0000 | [diff] [blame] | 85 | /* PR3917 */ |
| 86 | #line 41 |
| 87 | extern char array2[\ |
| 88 | _\ |
| 89 | _LINE__ == 42 ? 1: -1]; /* line marker is location of first _ */ |
| 90 | |
| 91 | |
| 92 | |