summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/attr-availability.c
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2015-03-19 19:18:22 +0000
committerNico Weber <nicolasweber@gmx.de>2015-03-19 19:18:22 +0000
commit0055a19926b7b23cfc49b5b645769698ba5aa129 (patch)
tree80013c2d762e266554b7c5e8c0e0b25640bf6598 /clang/test/Sema/attr-availability.c
parentf3d3db65de4e2937cd2efa3de984b2d35c9ec5c0 (diff)
downloadbcm5719-llvm-0055a19926b7b23cfc49b5b645769698ba5aa129.tar.gz
bcm5719-llvm-0055a19926b7b23cfc49b5b645769698ba5aa129.zip
Add -Wpartial-availability.
This warns when using decls that are not available on all deployment targets. For example, a call to - (void)ppartialMethod __attribute__((availability(macosx,introduced=10.8))); will warn if -mmacosx-version-min is set to less than 10.8. To silence the warning, one has to explicitly redeclare the method like so: @interface Whatever(MountainLionAPI) - (void)ppartialMethod; @end This way, one cannot accidentally call a function that isn't available everywhere. Having to add the redeclaration will hopefully remind the user to add an explicit respondsToSelector: call as well. Some projects build against old SDKs to get this effect, but building against old SDKs suppresses some bug fixes -- see http://crbug.com/463171 for examples. The hope is that SDK headers are annotated well enough with availability attributes that new SDK + this warning offers the same amount of protection as using an old SDK. llvm-svn: 232750
Diffstat (limited to 'clang/test/Sema/attr-availability.c')
-rw-r--r--clang/test/Sema/attr-availability.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/Sema/attr-availability.c b/clang/test/Sema/attr-availability.c
index b7a8e6ef0f5..48bdf26598c 100644
--- a/clang/test/Sema/attr-availability.c
+++ b/clang/test/Sema/attr-availability.c
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -D WARN_PARTIAL -Wpartial-availability -triple x86_64-apple-darwin9 -fsyntax-only -fblocks -verify %s
+//
void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in OS X version 10.2 before it was introduced in version 10.4; attribute ignored}}
void f1() __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0))); // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}}
@@ -13,9 +15,32 @@ ATSFontGetName(const char *oName) __attribute__((availability(macosx,introduced=
extern void
ATSFontGetPostScriptName(int flags) __attribute__((availability(macosx,introduced=8.0,obsoleted=9.0, message="use ATSFontGetFullPostScriptName"))); // expected-note {{'ATSFontGetPostScriptName' has been explicitly marked unavailable here}}
+#if defined(WARN_PARTIAL)
+// expected-note@+3 {{has been explicitly marked partial here}}
+#endif
+extern void
+PartiallyAvailable() __attribute__((availability(macosx,introduced=10.8)));
+
+enum __attribute__((availability(macosx,introduced=10.8))) PartialEnum {
+ kPartialEnumConstant,
+};
+
void test_10095131() {
ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in OS X 9.0 - use CTFontCopyFullName}}
ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in OS X 9.0 - use ATSFontGetFullPostScriptName}}
+
+#if defined(WARN_PARTIAL)
+ // expected-warning@+2 {{is partial: introduced in OS X 10.8}} expected-note@+2 {{explicitly redeclare 'PartiallyAvailable' to silence this warning}}
+#endif
+ PartiallyAvailable();
+}
+
+extern void PartiallyAvailable() ;
+void with_redeclaration() {
+ PartiallyAvailable(); // Don't warn.
+
+ // enums should never warn.
+ enum PartialEnum p = kPartialEnumConstant;
}
// rdar://10711037
OpenPOWER on IntegriCloud