xref: /aosp_15_r20/external/clang/test/Sema/attr-unavailable-message.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li // rdar: //6734520
3*67e74705SXin Li 
4*67e74705SXin Li int foo(int)  __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{'foo' has been explicitly marked unavailable here}}
5*67e74705SXin Li double dfoo(double)  __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{'dfoo' has been explicitly marked unavailable here}}
6*67e74705SXin Li 
7*67e74705SXin Li void bar() __attribute__((__unavailable__)); // expected-note {{explicitly marked unavailable}}
8*67e74705SXin Li 
9*67e74705SXin Li int quux(void) __attribute__((__unavailable__(12))); // expected-error {{'__unavailable__' attribute requires a string}}
10*67e74705SXin Li 
11*67e74705SXin Li #define ACCEPTABLE	"Use something else"
12*67e74705SXin Li int quux2(void) __attribute__((__unavailable__(ACCEPTABLE)));
13*67e74705SXin Li 
test_foo()14*67e74705SXin Li void test_foo() {
15*67e74705SXin Li   int ir = foo(1); // expected-error {{'foo' is unavailable: USE IFOO INSTEAD}}
16*67e74705SXin Li   double dr = dfoo(1.0); // expected-error {{'dfoo' is unavailable: NO LONGER}}
17*67e74705SXin Li 
18*67e74705SXin Li   void (*fp)() = &bar; // expected-error {{'bar' is unavailable}}
19*67e74705SXin Li 
20*67e74705SXin Li   double (*fp4)(double) = dfoo;  // expected-error {{'dfoo' is unavailable: NO LONGER}}
21*67e74705SXin Li }
22*67e74705SXin Li 
23*67e74705SXin Li char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1];
24*67e74705SXin Li 
25*67e74705SXin Li // rdar://9623855
26*67e74705SXin Li void unavail(void)  __attribute__((__unavailable__));
unavail(void)27*67e74705SXin Li void unavail(void) {
28*67e74705SXin Li   // No complains inside an unavailable function.
29*67e74705SXin Li   int ir = foo(1);
30*67e74705SXin Li   double dr = dfoo(1.0);
31*67e74705SXin Li   void (*fp)() = &bar;
32*67e74705SXin Li   double (*fp4)(double) = dfoo;
33*67e74705SXin Li }
34*67e74705SXin Li 
35*67e74705SXin Li // rdar://10201690
36*67e74705SXin Li enum foo {
37*67e74705SXin Li     a = 1, // expected-note {{'a' has been explicitly marked deprecated here}}
38*67e74705SXin Li     b __attribute__((deprecated())) = 2, // expected-note {{'b' has been explicitly marked deprecated here}}
39*67e74705SXin Li     c = 3
40*67e74705SXin Li }__attribute__((deprecated()));
41*67e74705SXin Li 
42*67e74705SXin Li enum fee { // expected-note {{'fee' has been explicitly marked unavailable here}}
43*67e74705SXin Li     r = 1, // expected-note {{'r' has been explicitly marked unavailable here}}
44*67e74705SXin Li     s = 2,
45*67e74705SXin Li     t = 3
46*67e74705SXin Li }__attribute__((unavailable()));
47*67e74705SXin Li 
f()48*67e74705SXin Li enum fee f() { // expected-error {{'fee' is unavailable}}
49*67e74705SXin Li     int i = a; // expected-warning {{'a' is deprecated}}
50*67e74705SXin Li 
51*67e74705SXin Li     i = b; // expected-warning {{'b' is deprecated}}
52*67e74705SXin Li 
53*67e74705SXin Li     return r; // expected-error {{'r' is unavailable}}
54*67e74705SXin Li }
55