[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / attr-deprecated-c2x.c
blobd0d763443b449db4680b6ac6cc0db011aa2d4488
1 // RUN: %clang_cc1 %s -verify -fsyntax-only -std=c2x
3 [[deprecated]] int f(void); // expected-note 2 {{'f' has been explicitly marked deprecated here}}
4 [[deprecated]] void g(void);// expected-note {{'g' has been explicitly marked deprecated here}}
5 void g(void);
7 extern int var [[deprecated]]; // expected-note 2 {{'var' has been explicitly marked deprecated here}}
9 int a(void) {
10 int (*ptr)(void) = f; // expected-warning {{'f' is deprecated}}
11 f(); // expected-warning {{'f' is deprecated}}
13 // test if attributes propagate to functions
14 g(); // expected-warning {{'g' is deprecated}}
16 return var; // expected-warning {{'var' is deprecated}}
19 // test if attributes propagate to variables
20 extern int var;
21 int w(void) {
22 return var; // expected-warning {{'var' is deprecated}}
25 [[deprecated]] int old_fn(void);// expected-note {{'old_fn' has been explicitly marked deprecated here}}
26 int old_fn(void);
27 int (*fn_ptr)(void) = old_fn; // expected-warning {{'old_fn' is deprecated}}
29 int old_fn(void) {
30 return old_fn()+1; // no warning, deprecated functions can use deprecated symbols.
33 struct foo {
34 int x [[deprecated]]; // expected-note 3 {{'x' has been explicitly marked deprecated here}}
37 void 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}}
43 typedef struct foo foo_dep [[deprecated]]; // expected-note {{'foo_dep' has been explicitly marked deprecated here}}
44 foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}}
46 struct [[deprecated, // expected-note {{'bar_dep' has been explicitly marked deprecated here}}
47 invalid_attribute]] bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
49 struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}}
51 [[deprecated("this is the message")]] int i; // expected-note {{'i' has been explicitly marked deprecated here}}
52 void test4(void) {
53 i = 12; // expected-warning {{'i' is deprecated: this is the message}}
56 // Ensure that deprecated only accepts one argument, not the replacement
57 // argument supported as a GNU extension.
58 [[deprecated("message", "replacement not supported")]] void test5(void); // expected-error {{'deprecated' attribute takes no more than 1 argument}}