Home | History | Annotate | Download | only in Preprocessor
      1 // RUN: %clang_cc1 -std=c99 -fsyntax-only -verify -pedantic %s
      2 // RUN: not %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: ABC'
      3 // RUN: not %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: DEF'
      4 
      5 #line 'a'            // expected-error {{#line directive requires a positive integer argument}}
      6 #line 0              // expected-warning {{#line directive with zero argument is a GNU extension}}
      7 #line 00             // expected-warning {{#line directive with zero argument is a GNU extension}}
      8 #line 2147483648     // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}}
      9 #line 42             // ok
     10 #line 42 'a'         // expected-error {{invalid filename for #line directive}}
     11 #line 42 "foo/bar/baz.h"  // ok
     12 
     13 
     14 // #line directives expand macros.
     15 #define A 42 "foo"
     16 #line A
     17 
     18 # 42
     19 # 42 "foo"
     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}}
     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}}
     32 # 42a33          // expected-error {{GNU line marker directive requires a simple digit sequence}}
     33 
     34 // These are checked by the RUN line.
     35 #line 92 "blonk.c"
     36 #error ABC
     37 #error DEF
     38 // expected-error@-2 {{ABC}}
     39 #line 150
     40 // expected-error@-3 {{DEF}}
     41 
     42 
     43 // Verify that linemarker diddling of the system header flag works.
     44 
     45 # 192 "glomp.h" // not a system header.
     46 typedef int x;  // expected-note {{previous definition is here}}
     47 typedef int x;  // expected-warning {{redefinition of typedef 'x' is a C11 feature}}
     48 
     49 # 192 "glomp.h" 3 // System header.
     50 typedef int y;  // ok
     51 typedef int y;  // ok
     52 
     53 typedef int q;  // q is in system header.
     54 
     55 #line 42 "blonk.h"  // doesn't change system headerness.
     56 
     57 typedef int z;  // ok
     58 typedef int z;  // ok
     59 
     60 # 97     // doesn't change system headerness.
     61 
     62 typedef int z1;  // ok
     63 typedef int z1;  // ok
     64 
     65 # 42 "blonk.h"  // DOES change system headerness.
     66 
     67 typedef int w;  // expected-note {{previous definition is here}}
     68 typedef int w;  // expected-warning {{redefinition of typedef 'w' is a C11 feature}}
     69 
     70 typedef int q;  // original definition in system header, should not diagnose.
     71 
     72 // This should not produce an "extra tokens at end of #line directive" warning,
     73 // because #line is allowed to contain expanded tokens.
     74 #define EMPTY()
     75 #line 2 "foo.c" EMPTY( )
     76 #line 2 "foo.c" NONEMPTY( )  // expected-warning{{extra tokens at end of #line directive}}
     77 
     78 // PR3940
     79 #line 0xf  // expected-error {{#line directive requires a simple digit sequence}}
     80 #line 42U  // expected-error {{#line directive requires a simple digit sequence}}
     81 
     82 
     83 // Line markers are digit strings interpreted as decimal numbers, this is
     84 // 10, not 8.
     85 #line 010  // expected-warning {{#line directive interprets number as decimal, not octal}}
     86 extern int array[__LINE__ == 10 ? 1:-1];
     87 
     88 # 020      // expected-warning {{GNU line marker directive interprets number as decimal, not octal}}
     89 extern int array_gnuline[__LINE__ == 20 ? 1:-1];
     90 
     91 /* PR3917 */
     92 #line 41
     93 extern char array2[\
     94 _\
     95 _LINE__ == 42 ? 1: -1];  /* line marker is location of first _ */
     96 
     97 # 51
     98 extern char array2_gnuline[\
     99 _\
    100 _LINE__ == 52 ? 1: -1];  /* line marker is location of first _ */
    101 
    102 // rdar://11550996
    103 #line 0 "line-directive.c" // expected-warning {{#line directive with zero argument is a GNU extension}}
    104 undefined t; // expected-error {{unknown type name 'undefined'}}
    105 
    106 
    107