xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/attr-unavailable.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc int &foo(int); // expected-note {{candidate}}
4f4a2713aSLionel Sambuc double &foo(double); // expected-note {{candidate}}
5f4a2713aSLionel Sambuc void foo(...) __attribute__((__unavailable__)); // expected-note {{candidate function}} \
6*0a6a1f1dSLionel Sambuc // expected-note{{'foo' has been explicitly marked unavailable here}}
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc void bar(...) __attribute__((__unavailable__)); // expected-note 2{{explicitly marked unavailable}}
9f4a2713aSLionel Sambuc 
test_foo(short * sp)10f4a2713aSLionel Sambuc void test_foo(short* sp) {
11f4a2713aSLionel Sambuc   int &ir = foo(1);
12f4a2713aSLionel Sambuc   double &dr = foo(1.0);
13f4a2713aSLionel Sambuc   foo(sp); // expected-error{{call to unavailable function 'foo'}}
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc   void (*fp)(...) = &bar; // expected-error{{'bar' is unavailable}}
16f4a2713aSLionel Sambuc   void (*fp2)(...) = bar; // expected-error{{'bar' is unavailable}}
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc   int &(*fp3)(int) = foo;
19f4a2713aSLionel Sambuc   void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}}
20f4a2713aSLionel Sambuc }
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc namespace radar9046492 {
23f4a2713aSLionel Sambuc // rdar://9046492
24f4a2713aSLionel Sambuc #define FOO __attribute__((unavailable("not available - replaced")))
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc void foo() FOO; // expected-note {{candidate function has been explicitly made unavailable}}
bar()27f4a2713aSLionel Sambuc void bar() {
28f4a2713aSLionel Sambuc   foo(); // expected-error {{call to unavailable function 'foo': not available - replaced}}
29f4a2713aSLionel Sambuc }
30f4a2713aSLionel Sambuc }
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc void unavail(short* sp)  __attribute__((__unavailable__));
unavail(short * sp)33f4a2713aSLionel Sambuc void unavail(short* sp) {
34f4a2713aSLionel Sambuc   // No complains inside an unavailable function.
35f4a2713aSLionel Sambuc   int &ir = foo(1);
36f4a2713aSLionel Sambuc   double &dr = foo(1.0);
37f4a2713aSLionel Sambuc   foo(sp);
38f4a2713aSLionel Sambuc   foo();
39f4a2713aSLionel Sambuc }
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc // Show that delayed processing of 'unavailable' is the same
42*0a6a1f1dSLionel Sambuc // delayed process for 'deprecated'.
43*0a6a1f1dSLionel Sambuc // <rdar://problem/12241361> and <rdar://problem/15584219>
44*0a6a1f1dSLionel Sambuc enum DeprecatedEnum { DE_A, DE_B } __attribute__((deprecated)); // expected-note {{'DeprecatedEnum' has been explicitly marked deprecated here}}
45*0a6a1f1dSLionel Sambuc __attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
46*0a6a1f1dSLionel Sambuc typedef enum DeprecatedEnum AnotherDeprecatedEnum; // expected-warning {{'DeprecatedEnum' is deprecated}}
47*0a6a1f1dSLionel Sambuc 
48*0a6a1f1dSLionel Sambuc __attribute__((deprecated))
testDeprecated(DeprecatedEnum X)49*0a6a1f1dSLionel Sambuc DeprecatedEnum testDeprecated(DeprecatedEnum X) { return X; }
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc enum UnavailableEnum { UE_A, UE_B } __attribute__((unavailable)); // expected-note {{'UnavailableEnum' has been explicitly marked unavailable here}}
53*0a6a1f1dSLionel Sambuc __attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
54*0a6a1f1dSLionel Sambuc typedef enum UnavailableEnum AnotherUnavailableEnum; // expected-error {{'UnavailableEnum' is unavailable}}
55*0a6a1f1dSLionel Sambuc 
56*0a6a1f1dSLionel Sambuc 
57*0a6a1f1dSLionel Sambuc __attribute__((unavailable))
testUnavailable(UnavailableEnum X)58*0a6a1f1dSLionel Sambuc UnavailableEnum testUnavailable(UnavailableEnum X) { return X; }
59