{"id":11166,"date":"2015-05-08T09:34:19","date_gmt":"2015-05-08T13:34:19","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=11166"},"modified":"2016-11-11T15:12:56","modified_gmt":"2016-11-11T20:12:56","slug":"clangs-new-wpartial-availability","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2015\/05\/08\/clangs-new-wpartial-availability\/","title":{"rendered":"Clang\u2019s New -Wpartial-availability"},"content":{"rendered":"<p><a href=\"http:\/\/llvm.org\/viewvc\/llvm-project?view=revision&amp;revision=232750\">Clang<\/a> (via <a href=\"https:\/\/twitter.com\/mattstevens\/status\/578703678900723712\">Matt Stevens<\/a>):<\/p>\r\n<blockquote cite=\"http:\/\/llvm.org\/viewvc\/llvm-project?view=revision&amp;revision=232750\"><p>This warns when using decls that are not available on all deployment targets.\r\nFor example, a call to<\/p>\r\n<pre>- (void)ppartialMethod __attribute__((availability(macosx,introduced=10.8)));<\/pre>\r\n<p>will warn if <tt>-mmacosx-version-min<\/tt> is set to less than 10.8.<\/p>\r\n<p>To silence the warning, one has to explicitly redeclare the method like so:<\/p>\r\n<pre>@interface Whatever(MountainLionAPI)\r\n- (void)ppartialMethod;\r\n@end\r\n<\/pre>\r\n<p>This way, one cannot accidentally call a function that isn't available\r\neverywhere.  Having to add the redeclaration will hopefully remind the user\r\nto add an explicit <code>respondsToSelector:<\/code> call as well.<\/p><\/blockquote>\r\n<p>I&rsquo;m not sure why this wasn&rsquo;t added years ago, when Apple stopped supporting older SDKs, but it&rsquo;s good to finally have it.<\/p>\r\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2013\/03\/15\/deploymate-1-0\/\">Deploymate 1.0<\/a>.<\/p>\r\n<p>Update (2016-11-11): My strategy is to add <tt>-Wpartial-availability<\/tt> to the <tt>WARNING_CFLAGS<\/tt>, and then wherever I have a runtime test for the OS version I bracket the code with:<\/p>\r\n<pre>#pragma clang diagnostic push\r\n#pragma clang diagnostic ignored \"-Wpartial-availability\"\r\n\/\/ Code that uses partially available APIs.\r\n#pragma clang diagnostic pop\r\n<\/pre>\r\n<p>Any warnings that this does not suppress represent code that needs to have a runtime check added. This seems to be more reliable than Deploymate and has the advantage of being checked every time I compile.<\/p>\r\n<p>Due to <a href=\"https:\/\/twitter.com\/steipete\/status\/717966560590225408\">problems<\/a> inside <code>XCTest<\/code>, it is necessary to not use <tt>-Wpartial-availability<\/tt> in test-related code.<\/p>","protected":false},"excerpt":{"rendered":"<p>Clang (via Matt Stevens): 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, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[230,255,31,229,30,71,226],"class_list":["post-11166","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-clang","tag-compiler","tag-ios","tag-llvm","tag-mac","tag-programming","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=11166"}],"version-history":[{"count":5,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11166\/revisions"}],"predecessor-version":[{"id":16344,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/11166\/revisions\/16344"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=11166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=11166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=11166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}