llvm-project/clang/test/SemaCXX/attr-unavailable.cpp

40 lines
1.3 KiB
C++
Raw Normal View History

// RUN: %clang_cc1 -fsyntax-only -verify %s
int &foo(int); // expected-note {{candidate}}
double &foo(double); // expected-note {{candidate}}
void foo(...) __attribute__((__unavailable__)); // expected-note {{candidate function}} \
// expected-note{{function has been explicitly marked unavailable here}}
void bar(...) __attribute__((__unavailable__)); // expected-note 2{{explicitly marked unavailable}}
void test_foo(short* sp) {
int &ir = foo(1);
double &dr = foo(1.0);
foo(sp); // expected-error{{call to unavailable function 'foo'}}
void (*fp)(...) = &bar; // expected-error{{'bar' is unavailable}}
void (*fp2)(...) = bar; // expected-error{{'bar' is unavailable}}
int &(*fp3)(int) = foo;
void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}}
}
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}}
}
}
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();
}