attr-deprecated.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // RUN: %clang_cc1 %s -verify -fsyntax-only
  2. int f() __attribute__((deprecated)); // expected-note 2 {{'f' has been explicitly marked deprecated here}}
  3. void g() __attribute__((deprecated));
  4. void g(); // expected-note {{'g' has been explicitly marked deprecated here}}
  5. extern int var __attribute__((deprecated)); // expected-note {{'var' has been explicitly marked deprecated here}}
  6. int a() {
  7. int (*ptr)() = f; // expected-warning {{'f' is deprecated}}
  8. f(); // expected-warning {{'f' is deprecated}}
  9. // test if attributes propagate to functions
  10. g(); // expected-warning {{'g' is deprecated}}
  11. return var; // expected-warning {{'var' is deprecated}}
  12. }
  13. // test if attributes propagate to variables
  14. extern int var; // expected-note {{'var' has been explicitly marked deprecated here}}
  15. int w() {
  16. return var; // expected-warning {{'var' is deprecated}}
  17. }
  18. int old_fn() __attribute__ ((deprecated));
  19. int old_fn(); // expected-note {{'old_fn' has been explicitly marked deprecated here}}
  20. int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
  21. int old_fn() {
  22. return old_fn()+1; // no warning, deprecated functions can use deprecated symbols.
  23. }
  24. struct foo {
  25. int x __attribute__((deprecated)); // expected-note 3 {{'x' has been explicitly marked deprecated here}}
  26. };
  27. void test1(struct foo *F) {
  28. ++F->x; // expected-warning {{'x' is deprecated}}
  29. struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}}
  30. struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}}
  31. }
  32. typedef struct foo foo_dep __attribute__((deprecated)); // expected-note 12 {{'foo_dep' has been explicitly marked deprecated here}}
  33. foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}}
  34. struct __attribute__((deprecated,
  35. invalid_attribute)) bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}} expected-note 2 {{'bar_dep' has been explicitly marked deprecated here}}
  36. struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}}
  37. // These should not warn because the actually declaration itself is deprecated.
  38. // rdar://6756623
  39. foo_dep *test4 __attribute__((deprecated));
  40. struct bar_dep *test5 __attribute__((deprecated));
  41. typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \
  42. // expected-warning {{'bar_dep' is deprecated}}
  43. typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated));
  44. int test8(char *p) {
  45. p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
  46. foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}}
  47. ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}}
  48. int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
  49. return func(ptr);
  50. }
  51. foo_dep *test9(void) __attribute__((deprecated));
  52. foo_dep *test9(void) {
  53. void* myalloc(unsigned long);
  54. foo_dep *ptr
  55. = (foo_dep*)
  56. myalloc(sizeof(foo_dep));
  57. return ptr;
  58. }
  59. void test10(void) __attribute__((deprecated));
  60. void test10(void) {
  61. if (sizeof(foo_dep) == sizeof(void*)) {
  62. }
  63. foo_dep *localfunc(void);
  64. foo_dep localvar;
  65. }
  66. char test11[sizeof(foo_dep)] __attribute__((deprecated));
  67. char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}}
  68. int test13(foo_dep *foo) __attribute__((deprecated));
  69. int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
  70. unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
  71. unsigned long test16 __attribute__((deprecated))
  72. = sizeof(foo_dep);
  73. foo_dep test17, // expected-warning {{'foo_dep' is deprecated}}
  74. test18 __attribute__((deprecated)),
  75. test19;
  76. // rdar://problem/8518751
  77. enum __attribute__((deprecated)) Test20 { // expected-note {{'Test20' has been explicitly marked deprecated here}}
  78. test20_a __attribute__((deprecated)), // expected-note {{'test20_a' has been explicitly marked deprecated here}}
  79. test20_b // expected-note {{'test20_b' has been explicitly marked deprecated here}}
  80. };
  81. void test20() {
  82. enum Test20 f; // expected-warning {{'Test20' is deprecated}}
  83. f = test20_a; // expected-warning {{'test20_a' is deprecated}}
  84. f = test20_b; // expected-warning {{'test20_b' is deprecated}}
  85. }
  86. char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
  87. struct test22 {
  88. foo_dep a __attribute((deprecated));
  89. foo_dep b; // expected-warning {{'foo_dep' is deprecated}}
  90. foo_dep c, d __attribute((deprecated)); // expected-warning {{'foo_dep' is deprecated}}
  91. __attribute((deprecated)) foo_dep e, f;
  92. };
  93. typedef int test23_ty __attribute((deprecated));
  94. typedef int test23_ty; // expected-note {{'test23_ty' has been explicitly marked deprecated here}}
  95. test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}}