line-directive.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #line 'a' // expected-error {{#line directive requires a positive integer argument}}
  5. #line 0 // expected-warning {{#line directive with zero argument is a GNU extension}}
  6. #line 00 // expected-warning {{#line directive with zero argument is a GNU extension}}
  7. #line 2147483648 // expected-warning {{C requires #line number to be less than 2147483648, allowed as extension}}
  8. #line 42 // ok
  9. #line 42 'a' // expected-error {{invalid filename for #line directive}}
  10. #line 42 "foo/bar/baz.h" // ok
  11. // #line directives expand macros.
  12. #define A 42 "foo"
  13. #line A
  14. # 42
  15. # 42 "foo"
  16. # 42 "foo" 2 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
  17. # 42 "foo" 1 3 // enter
  18. # 42 "foo" 2 3 // exit
  19. # 42 "foo" 2 3 4 // expected-error {{invalid line marker flag '2': cannot pop empty include stack}}
  20. # 42 "foo" 3 4
  21. # 'a' // expected-error {{invalid preprocessing directive}}
  22. # 42 'f' // expected-error {{invalid filename for line marker directive}}
  23. # 42 1 3 // expected-error {{invalid filename for line marker directive}}
  24. # 42 "foo" 3 1 // expected-error {{invalid flag line marker directive}}
  25. # 42 "foo" 42 // expected-error {{invalid flag line marker directive}}
  26. # 42 "foo" 1 2 // expected-error {{invalid flag line marker directive}}
  27. # 42a33 // expected-error {{GNU line marker directive requires a simple digit sequence}}
  28. // These are checked by the RUN line.
  29. #line 92 "blonk.c"
  30. #error ABC
  31. #error DEF
  32. // expected-error@-2 {{ABC}}
  33. #line 150
  34. // expected-error@-3 {{DEF}}
  35. // Verify that linemarker diddling of the system header flag works.
  36. # 192 "glomp.h" // not a system header.
  37. typedef int x; // expected-note {{previous definition is here}}
  38. typedef int x; // expected-warning {{redefinition of typedef 'x' is a C11 feature}}
  39. # 192 "glomp.h" 3 // System header.
  40. typedef int y; // ok
  41. typedef int y; // ok
  42. typedef int q; // q is in system header.
  43. #line 42 "blonk.h" // doesn't change system headerness.
  44. typedef int z; // ok
  45. typedef int z; // ok
  46. # 97 // doesn't change system headerness.
  47. typedef int z1; // ok
  48. typedef int z1; // ok
  49. # 42 "blonk.h" // DOES change system headerness.
  50. typedef int w; // expected-note {{previous definition is here}}
  51. typedef int w; // expected-warning {{redefinition of typedef 'w' is a C11 feature}}
  52. typedef int q; // original definition in system header, should not diagnose.
  53. // This should not produce an "extra tokens at end of #line directive" warning,
  54. // because #line is allowed to contain expanded tokens.
  55. #define EMPTY()
  56. #line 2 "foo.c" EMPTY( )
  57. #line 2 "foo.c" NONEMPTY( ) // expected-warning{{extra tokens at end of #line directive}}
  58. // PR3940
  59. #line 0xf // expected-error {{#line directive requires a simple digit sequence}}
  60. #line 42U // expected-error {{#line directive requires a simple digit sequence}}
  61. // Line markers are digit strings interpreted as decimal numbers, this is
  62. // 10, not 8.
  63. #line 010 // expected-warning {{#line directive interprets number as decimal, not octal}}
  64. extern int array[__LINE__ == 10 ? 1:-1];
  65. # 020 // expected-warning {{GNU line marker directive interprets number as decimal, not octal}}
  66. extern int array_gnuline[__LINE__ == 20 ? 1:-1];
  67. /* PR3917 */
  68. #line 41
  69. extern char array2[\
  70. _\
  71. _LINE__ == 42 ? 1: -1]; /* line marker is location of first _ */
  72. # 51
  73. extern char array2_gnuline[\
  74. _\
  75. _LINE__ == 52 ? 1: -1]; /* line marker is location of first _ */
  76. // rdar://11550996
  77. #line 0 "line-directive.c" // expected-warning {{#line directive with zero argument is a GNU extension}}
  78. undefined t; // expected-error {{unknown type name 'undefined'}}