2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-02-18 14:34:51 +08:00
|
|
|
|
2010-01-08 12:41:39 +08:00
|
|
|
int &foo(int); // expected-note {{candidate}}
|
|
|
|
double &foo(double); // expected-note {{candidate}}
|
2009-02-19 05:56:37 +08:00
|
|
|
void foo(...) __attribute__((__unavailable__)); // expected-note {{candidate function}} \
|
2013-12-19 07:30:06 +08:00
|
|
|
// expected-note{{'foo' has been explicitly marked unavailable here}}
|
2009-02-19 05:56:37 +08:00
|
|
|
|
2016-02-27 03:27:00 +08:00
|
|
|
void bar(...) __attribute__((__unavailable__)); // expected-note 2{{explicitly marked unavailable}} \
|
|
|
|
// expected-note 2{{candidate function has been explicitly made unavailable}}
|
2009-02-18 14:34:51 +08:00
|
|
|
|
|
|
|
void test_foo(short* sp) {
|
|
|
|
int &ir = foo(1);
|
|
|
|
double &dr = foo(1.0);
|
2009-02-19 05:56:37 +08:00
|
|
|
foo(sp); // expected-error{{call to unavailable function 'foo'}}
|
|
|
|
|
2010-07-22 04:43:11 +08:00
|
|
|
void (*fp)(...) = &bar; // expected-error{{'bar' is unavailable}}
|
|
|
|
void (*fp2)(...) = bar; // expected-error{{'bar' is unavailable}}
|
2009-02-19 05:56:37 +08:00
|
|
|
|
|
|
|
int &(*fp3)(int) = foo;
|
2010-07-22 04:43:11 +08:00
|
|
|
void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}}
|
2009-02-18 14:34:51 +08:00
|
|
|
}
|
2011-02-26 02:38:59 +08:00
|
|
|
|
|
|
|
namespace radar9046492 {
|
|
|
|
// rdar://9046492
|
|
|
|
#define FOO __attribute__((unavailable("not available - replaced")))
|
|
|
|
|
|
|
|
void foo() FOO; // expected-note {{candidate function has been explicitly made unavailable}}
|
|
|
|
void bar() {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
foo(); // expected-error {{call to unavailable function 'foo': not available - replaced}}
|
2011-02-26 02:38:59 +08:00
|
|
|
}
|
|
|
|
}
|
2011-06-23 08:41:50 +08:00
|
|
|
|
|
|
|
void unavail(short* sp) __attribute__((__unavailable__));
|
|
|
|
void unavail(short* sp) {
|
|
|
|
// No complains inside an unavailable function.
|
|
|
|
int &ir = foo(1);
|
|
|
|
double &dr = foo(1.0);
|
|
|
|
foo(sp);
|
|
|
|
foo();
|
|
|
|
}
|
2013-12-19 07:30:06 +08:00
|
|
|
|
|
|
|
// Show that delayed processing of 'unavailable' is the same
|
|
|
|
// delayed process for 'deprecated'.
|
|
|
|
// <rdar://problem/12241361> and <rdar://problem/15584219>
|
|
|
|
enum DeprecatedEnum { DE_A, DE_B } __attribute__((deprecated)); // expected-note {{'DeprecatedEnum' has been explicitly marked deprecated here}}
|
|
|
|
__attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
|
|
|
|
typedef enum DeprecatedEnum AnotherDeprecatedEnum; // expected-warning {{'DeprecatedEnum' is deprecated}}
|
|
|
|
|
|
|
|
__attribute__((deprecated))
|
|
|
|
DeprecatedEnum testDeprecated(DeprecatedEnum X) { return X; }
|
|
|
|
|
|
|
|
|
|
|
|
enum UnavailableEnum { UE_A, UE_B } __attribute__((unavailable)); // expected-note {{'UnavailableEnum' has been explicitly marked unavailable here}}
|
|
|
|
__attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
|
|
|
|
typedef enum UnavailableEnum AnotherUnavailableEnum; // expected-error {{'UnavailableEnum' is unavailable}}
|
|
|
|
|
|
|
|
|
|
|
|
__attribute__((unavailable))
|
|
|
|
UnavailableEnum testUnavailable(UnavailableEnum X) { return X; }
|
2016-02-27 03:27:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Check that unavailable classes can be used as arguments to unavailable
|
|
|
|
// function, particularly in template functions.
|
|
|
|
#if !__has_feature(attribute_availability_in_templates)
|
|
|
|
#error "Missing __has_feature"
|
|
|
|
#endif
|
|
|
|
class __attribute((unavailable)) UnavailableClass; // \
|
|
|
|
expected-note 3{{'UnavailableClass' has been explicitly marked unavailable here}}
|
|
|
|
void unavail_class(UnavailableClass&); // expected-error {{'UnavailableClass' is unavailable}}
|
|
|
|
void unavail_class_marked(UnavailableClass&) __attribute__((unavailable));
|
|
|
|
template <class T> void unavail_class(UnavailableClass&); // expected-error {{'UnavailableClass' is unavailable}}
|
|
|
|
template <class T> void unavail_class_marked(UnavailableClass&) __attribute__((unavailable));
|
|
|
|
template <class T> void templated(T&);
|
|
|
|
void untemplated(UnavailableClass &UC) { // expected-error {{'UnavailableClass' is unavailable}}
|
|
|
|
templated(UC);
|
|
|
|
}
|
|
|
|
void untemplated_marked(UnavailableClass &UC) __attribute__((unavailable)) {
|
|
|
|
templated(UC);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void templated_calls_bar() { bar(); } // \
|
|
|
|
// expected-error{{call to unavailable function 'bar'}}
|
|
|
|
template <class T> void templated_calls_bar_arg(T v) { bar(v); } // \
|
|
|
|
// expected-error{{call to unavailable function 'bar'}}
|
|
|
|
template <class T> void templated_calls_bar_arg_never_called(T v) { bar(v); }
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void unavail_templated_calls_bar() __attribute__((unavailable)) { // \
|
|
|
|
expected-note{{candidate function [with T = int] has been explicitly made unavailable}}
|
|
|
|
bar(5);
|
|
|
|
}
|
|
|
|
template <class T>
|
|
|
|
void unavail_templated_calls_bar_arg(T v) __attribute__((unavailable)) { // \
|
|
|
|
expected-note{{candidate function [with T = int] has been explicitly made unavailable}}
|
|
|
|
bar(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void calls_templates_which_call_bar() {
|
|
|
|
templated_calls_bar<int>();
|
|
|
|
|
|
|
|
templated_calls_bar_arg(5); // \
|
|
|
|
expected-note{{in instantiation of function template specialization 'templated_calls_bar_arg<int>' requested here}}
|
|
|
|
|
|
|
|
unavail_templated_calls_bar<int>(); // \
|
|
|
|
expected-error{{call to unavailable function 'unavail_templated_calls_bar'}}
|
|
|
|
|
|
|
|
unavail_templated_calls_bar_arg(5); // \
|
|
|
|
expected-error{{call to unavailable function 'unavail_templated_calls_bar_arg'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void unavail_templated(T) __attribute__((unavailable)); // \
|
|
|
|
expected-note{{candidate function [with T = int] has been explicitly made unavailable}}
|
|
|
|
void calls_unavail_templated() {
|
|
|
|
unavail_templated(5); // expected-error{{call to unavailable function 'unavail_templated'}}
|
|
|
|
}
|
|
|
|
void unavail_calls_unavail_templated() __attribute__((unavailable)) {
|
|
|
|
unavail_templated(5);
|
|
|
|
}
|
Sema: Methods in unavailable classes are unavailable
Similar to the template cases in r262050, when a C++ method in an
unavailable struct/class calls unavailable API, don't diagnose an error.
I.e., this case was failing:
void foo() __attribute__((unavailable));
struct __attribute__((unavailable)) A {
void bar() { foo(); }
};
Since A is unavailable, A::bar is allowed to call foo. However, we were
emitting a diagnostic here. This commit checks up the context chain
from A::bar, in a manner inspired by SemaDeclAttr.cpp:isDeclUnavailable.
I expected to find other related issues but failed to trigger them:
- I wondered if DeclBase::getAvailability should check for
`TemplateDecl` instead of `FunctionTemplateDecl`, but I couldn't find
a way to trigger this. I left behind a few extra tests to make sure
we don't regress.
- I wondered if Sema::isFunctionConsideredUnavailable should be
symmetric, checking up the context chain of the callee (this commit
only checks up the context chain of the caller). However, I couldn't
think of a testcase that didn't require first referencing the
unavailable type; this, we already diagnose.
rdar://problem/25030656
llvm-svn: 262921
2016-03-08 18:28:52 +08:00
|
|
|
|
|
|
|
void unavailable() __attribute((unavailable)); // \
|
|
|
|
expected-note 4{{candidate function has been explicitly made unavailable}}
|
|
|
|
struct AvailableStruct {
|
|
|
|
void calls_unavailable() { unavailable(); } // \
|
|
|
|
expected-error{{call to unavailable function 'unavailable'}}
|
|
|
|
template <class U> void calls_unavailable() { unavailable(); } // \
|
|
|
|
expected-error{{call to unavailable function 'unavailable'}}
|
|
|
|
};
|
|
|
|
template <class T> struct AvailableStructTemplated {
|
|
|
|
void calls_unavailable() { unavailable(); } // \
|
|
|
|
expected-error{{call to unavailable function 'unavailable'}}
|
|
|
|
template <class U> void calls_unavailable() { unavailable(); } // \
|
|
|
|
expected-error{{call to unavailable function 'unavailable'}}
|
|
|
|
};
|
|
|
|
struct __attribute__((unavailable)) UnavailableStruct {
|
|
|
|
void calls_unavailable() { unavailable(); }
|
|
|
|
template <class U> void calls_unavailable() { unavailable(); }
|
|
|
|
};
|
|
|
|
template <class T> struct __attribute__((unavailable)) UnavailableStructTemplated {
|
|
|
|
void calls_unavailable() { unavailable(); }
|
|
|
|
template <class U> void calls_unavailable() { unavailable(); }
|
|
|
|
};
|