Clang Project

clang_source_code/test/Sema/attr-deprecated-c2x.c
1// RUN: %clang_cc1 %s -verify -fsyntax-only -fdouble-square-bracket-attributes
2
3int f() [[deprecated]]; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
4void g() [[deprecated]];// expected-note {{'g' has been explicitly marked deprecated here}}
5void g();
6
7extern int var [[deprecated]]; // expected-note 2 {{'var' has been explicitly marked deprecated here}}
8
9int a() {
10  int (*ptr)() = f; // expected-warning {{'f' is deprecated}}
11  f(); // expected-warning {{'f' is deprecated}}
12
13  // test if attributes propagate to functions
14  g(); // expected-warning {{'g' is deprecated}}
15
16  return var; // expected-warning {{'var' is deprecated}}
17}
18
19// test if attributes propagate to variables
20extern int var;
21int w() {
22  return var; // expected-warning {{'var' is deprecated}}
23}
24
25int old_fn() [[deprecated]];// expected-note {{'old_fn' has been explicitly marked deprecated here}}
26int old_fn();
27int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
28
29int old_fn() {
30  return old_fn()+1;  // no warning, deprecated functions can use deprecated symbols.
31}
32
33struct foo {
34  int x [[deprecated]]; // expected-note 3 {{'x' has been explicitly marked deprecated here}}
35};
36
37void test1(struct foo *F) {
38  ++F->x;  // expected-warning {{'x' is deprecated}}
39  struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}}
40  struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}}
41}
42
43typedef struct foo foo_dep [[deprecated]]; // expected-note {{'foo_dep' has been explicitly marked deprecated here}}
44foo_dep *test2;    // expected-warning {{'foo_dep' is deprecated}}
45
46struct [[deprecated, // expected-note {{'bar_dep' has been explicitly marked deprecated here}}
47         invalid_attribute]] bar_dep ;  // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
48
49struct bar_dep *test3;   // expected-warning {{'bar_dep' is deprecated}}
50
51[[deprecated("this is the message")]] int i; // expected-note {{'i' has been explicitly marked deprecated here}}
52void test4(void) {
53  i = 12; // expected-warning {{'i' is deprecated: this is the message}}
54}
55