attributes.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic -std=c99
  2. int __attribute__(()) x;
  3. __inline void __attribute__((__always_inline__, __nodebug__))
  4. foo(void) {
  5. }
  6. __attribute__(()) y; // expected-warning {{defaults to 'int'}}
  7. // PR2796
  8. int (__attribute__(()) *z)(long y);
  9. void f1(__attribute__(()) int x);
  10. int f2(y, __attribute__(()) x); // expected-error {{expected identifier}}
  11. // This is parsed as a normal argument list (with two args that are implicit
  12. // int) because the __attribute__ is a declspec.
  13. void f3(__attribute__(()) x, // expected-warning {{defaults to 'int'}}
  14. y); // expected-warning {{defaults to 'int'}}
  15. void f4(__attribute__(())); // expected-error {{expected parameter declarator}}
  16. // This is ok, the __attribute__ applies to the pointer.
  17. int baz(int (__attribute__(()) *x)(long y));
  18. void g1(void (*f1)(__attribute__(()) int x));
  19. void g2(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}}
  20. void g3(void (*f3)(__attribute__(()) x, int y)); // expected-warning {{defaults to 'int'}}
  21. void g4(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}}
  22. void (*h1)(void (*f1)(__attribute__(()) int x));
  23. void (*h2)(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}}
  24. void (*h3)(void (*f3)(__attribute__(()) x)); // expected-warning {{defaults to 'int'}}
  25. void (*h4)(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}}
  26. // rdar://6131260
  27. int foo42(void) {
  28. int x, __attribute__((unused)) y, z;
  29. return 0;
  30. }
  31. // rdar://6096491
  32. void __attribute__((noreturn)) d0(void), __attribute__((noreturn)) d1(void);
  33. void d2(void) __attribute__((noreturn)), d3(void) __attribute__((noreturn));
  34. // PR6287
  35. void __attribute__((returns_twice)) returns_twice_test();
  36. int aligned(int);
  37. int __attribute__((vec_type_hint(char, aligned(16) )) missing_rparen_1; // expected-error 2{{expected ')'}} expected-note {{to match}} expected-warning {{does not declare anything}}
  38. int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error {{expected ')'}}
  39. int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error {{expected ')'}}
  40. int testFundef1(int *a) __attribute__((nonnull(1))) { // \
  41. // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
  42. return *a;
  43. }
  44. // noreturn is lifted to type qualifier
  45. void testFundef2() __attribute__((noreturn)) { // \
  46. // expected-warning {{GCC does not allow 'noreturn' attribute in this position on a function definition}}
  47. testFundef2();
  48. }
  49. int testFundef3(int *a) __attribute__((nonnull(1), // \
  50. // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
  51. pure)) { // \
  52. // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
  53. return *a;
  54. }
  55. int testFundef4(int *a) __attribute__((nonnull(1))) // \
  56. // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
  57. __attribute((pure)) { // \
  58. // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
  59. return *a;
  60. }
  61. // GCC allows these
  62. void testFundef5() __attribute__(()) { }
  63. __attribute__((pure)) int testFundef6(int a) { return a; }
  64. void deprecatedTestFun(void) __attribute__((deprecated()));
  65. struct s {
  66. int a;
  67. };
  68. // This test ensure compatibility with parsing GNU-style attributes
  69. // where the attribute is on a separate line from the elaborated type
  70. // specifier.
  71. struct s
  72. __attribute__((used)) bar;