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