| 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
| 3 | int &foo(int); |
| 4 | double &foo(double); |
| 5 | void foo(...) __attribute__((__unavailable__)); // \ |
| 6 | // expected-note 2 {{'foo' has been explicitly marked unavailable here}} |
| 7 | |
| 8 | void bar(...) __attribute__((__unavailable__)); // expected-note 4 {{explicitly marked unavailable}} |
| 9 | |
| 10 | void test_foo(short* sp) { |
| 11 | int &ir = foo(1); |
| 12 | double &dr = foo(1.0); |
| 13 | foo(sp); // expected-error{{'foo' is unavailable}} |
| 14 | |
| 15 | void (*fp)(...) = &bar; // expected-error{{'bar' is unavailable}} |
| 16 | void (*fp2)(...) = bar; // expected-error{{'bar' is unavailable}} |
| 17 | |
| 18 | int &(*fp3)(int) = foo; |
| 19 | void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}} |
| 20 | } |
| 21 | |
| 22 | namespace radar9046492 { |
| 23 | // rdar://9046492 |
| 24 | #define FOO __attribute__((unavailable("not available - replaced"))) |
| 25 | |
| 26 | void foo() FOO; // expected-note{{'foo' has been explicitly marked unavailable here}} |
| 27 | void bar() { |
| 28 | foo(); // expected-error {{'foo' is unavailable: not available - replaced}} |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | void unavail(short* sp) __attribute__((__unavailable__)); |
| 33 | void unavail(short* sp) { |
| 34 | // No complains inside an unavailable function. |
| 35 | int &ir = foo(1); |
| 36 | double &dr = foo(1.0); |
| 37 | foo(sp); |
| 38 | foo(); |
| 39 | } |
| 40 | |
| 41 | // Show that delayed processing of 'unavailable' is the same |
| 42 | // delayed process for 'deprecated'. |
| 43 | // <rdar://problem/12241361> and <rdar://problem/15584219> |
| 44 | enum DeprecatedEnum { DE_A, DE_B } __attribute__((deprecated)); // expected-note {{'DeprecatedEnum' has been explicitly marked deprecated here}} |
| 45 | __attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum; |
| 46 | typedef enum DeprecatedEnum AnotherDeprecatedEnum; // expected-warning {{'DeprecatedEnum' is deprecated}} |
| 47 | |
| 48 | __attribute__((deprecated)) |
| 49 | DeprecatedEnum testDeprecated(DeprecatedEnum X) { return X; } |
| 50 | |
| 51 | |
| 52 | enum UnavailableEnum { UE_A, UE_B } __attribute__((unavailable)); // expected-note {{'UnavailableEnum' has been explicitly marked unavailable here}} |
| 53 | __attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum; |
| 54 | typedef enum UnavailableEnum AnotherUnavailableEnum; // expected-error {{'UnavailableEnum' is unavailable}} |
| 55 | |
| 56 | |
| 57 | __attribute__((unavailable)) |
| 58 | UnavailableEnum testUnavailable(UnavailableEnum X) { return X; } |
| 59 | |
| 60 | |
| 61 | // Check that unavailable classes can be used as arguments to unavailable |
| 62 | // function, particularly in template functions. |
| 63 | #if !__has_feature(attribute_availability_in_templates) |
| 64 | #error "Missing __has_feature" |
| 65 | #endif |
| 66 | class __attribute((unavailable)) UnavailableClass; // \ |
| 67 | expected-note 3{{'UnavailableClass' has been explicitly marked unavailable here}} |
| 68 | void unavail_class(UnavailableClass&); // expected-error {{'UnavailableClass' is unavailable}} |
| 69 | void unavail_class_marked(UnavailableClass&) __attribute__((unavailable)); |
| 70 | template <class T> void unavail_class(UnavailableClass&); // expected-error {{'UnavailableClass' is unavailable}} |
| 71 | template <class T> void unavail_class_marked(UnavailableClass&) __attribute__((unavailable)); |
| 72 | template <class T> void templated(T&); |
| 73 | void untemplated(UnavailableClass &UC) { // expected-error {{'UnavailableClass' is unavailable}} |
| 74 | templated(UC); |
| 75 | } |
| 76 | void untemplated_marked(UnavailableClass &UC) __attribute__((unavailable)) { |
| 77 | templated(UC); |
| 78 | } |
| 79 | |
| 80 | template <class T> void templated_calls_bar() { bar(); } // \ |
| 81 | // expected-error{{'bar' is unavailable}} |
| 82 | template <class T> void templated_calls_bar_arg(T v) { bar(v); } // \ |
| 83 | // expected-error{{'bar' is unavailable}} |
| 84 | template <class T> void templated_calls_bar_arg_never_called(T v) { bar(v); } |
| 85 | |
| 86 | template <class T> |
| 87 | void unavail_templated_calls_bar() __attribute__((unavailable)) { // \ |
| 88 | // expected-note {{'unavail_templated_calls_bar<int>' has been explicitly marked unavailable here}} |
| 89 | bar(5); |
| 90 | } |
| 91 | template <class T> |
| 92 | void unavail_templated_calls_bar_arg(T v) __attribute__((unavailable)) { |
| 93 | // expected-note@-1 {{'unavail_templated_calls_bar_arg<int>' has been explicitly marked unavailable here}} |
| 94 | bar(v); |
| 95 | } |
| 96 | |
| 97 | void calls_templates_which_call_bar() { |
| 98 | templated_calls_bar<int>(); |
| 99 | |
| 100 | templated_calls_bar_arg(5); // \ |
| 101 | expected-note{{in instantiation of function template specialization 'templated_calls_bar_arg<int>' requested here}} |
| 102 | |
| 103 | unavail_templated_calls_bar<int>(); // \ |
| 104 | expected-error{{'unavail_templated_calls_bar<int>' is unavailable}} |
| 105 | |
| 106 | unavail_templated_calls_bar_arg(5); // \ |
| 107 | expected-error{{'unavail_templated_calls_bar_arg<int>' is unavailable}} |
| 108 | } |
| 109 | |
| 110 | template <class T> void unavail_templated(T) __attribute__((unavailable)); |
| 111 | // expected-note@-1 {{'unavail_templated<int>' has been explicitly marked unavailable here}} |
| 112 | void calls_unavail_templated() { |
| 113 | unavail_templated(5); // expected-error{{'unavail_templated<int>' is unavailable}} |
| 114 | } |
| 115 | void unavail_calls_unavail_templated() __attribute__((unavailable)) { |
| 116 | unavail_templated(5); |
| 117 | } |
| 118 | |
| 119 | void unavailable() __attribute((unavailable)); |
| 120 | // expected-note@-1 4 {{'unavailable' has been explicitly marked unavailable here}} |
| 121 | struct AvailableStruct { |
| 122 | void calls_unavailable() { unavailable(); } // \ |
| 123 | expected-error{{'unavailable' is unavailable}} |
| 124 | template <class U> void calls_unavailable() { unavailable(); } // \ |
| 125 | expected-error{{'unavailable' is unavailable}} |
| 126 | }; |
| 127 | template <class T> struct AvailableStructTemplated { |
| 128 | void calls_unavailable() { unavailable(); } // \ |
| 129 | expected-error{{'unavailable' is unavailable}} |
| 130 | template <class U> void calls_unavailable() { unavailable(); } // \ |
| 131 | expected-error{{'unavailable' is unavailable}} |
| 132 | }; |
| 133 | struct __attribute__((unavailable)) UnavailableStruct { |
| 134 | void calls_unavailable() { unavailable(); } |
| 135 | template <class U> void calls_unavailable() { unavailable(); } |
| 136 | }; |
| 137 | template <class T> struct __attribute__((unavailable)) UnavailableStructTemplated { |
| 138 | void calls_unavailable() { unavailable(); } |
| 139 | template <class U> void calls_unavailable() { unavailable(); } |
| 140 | }; |
| 141 | |
| 142 | int unavailable_int() __attribute__((unavailable)); // expected-note 2 {{'unavailable_int' has been explicitly marked unavailable here}} |
| 143 | int has_default_arg(int x = unavailable_int()) { // expected-error{{'unavailable_int' is unavailable}} |
| 144 | return x; |
| 145 | } |
| 146 | |
| 147 | int has_default_arg2(int x = unavailable_int()) __attribute__((unavailable)) { |
| 148 | return x; |
| 149 | } |
| 150 | |
| 151 | template <class T> |
| 152 | T unavailable_template() __attribute__((unavailable)); |
| 153 | // expected-note@-1 {{'unavailable_template<int>' has been explicitly marked unavailable here}} |
| 154 | |
| 155 | template <class T> |
| 156 | int has_default_arg_template(T x = unavailable_template<T>()) {} |
| 157 | // expected-error@-1 {{'unavailable_template<int>' is unavailable}} |
| 158 | |
| 159 | int instantiate_it = has_default_arg_template<int>(); |
| 160 | // expected-note@-1 {{in instantiation of default function argument expression for 'has_default_arg_template<int>' required here}} |
| 161 | |
| 162 | template <class T> |
| 163 | int has_default_arg_template2(T x = unavailable_template<T>()) |
| 164 | __attribute__((unavailable)) {} |
| 165 | |
| 166 | __attribute__((unavailable)) |
| 167 | int instantiate_it2 = has_default_arg_template2<int>(); |
| 168 | |
| 169 | template <class T> |
| 170 | int phase_one_unavailable(int x = unavailable_int()) {} |
| 171 | // expected-error@-1 {{'unavailable_int' is unavailable}} |
| 172 | |
| 173 | template <class T> |
| 174 | int phase_one_unavailable2(int x = unavailable_int()) __attribute__((unavailable)) {} |
| 175 | |