"Unsupported Availability Guard" Warning

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

"Unsupported Availability Guard" Warning

Tom Stellard via cfe-dev
Hello LLVM / Clang devs,

I wanted to ask about the purpose of the warning that appears when you try to combine an `@available()` statement with anything else (`Wunsupported-availability-guard`). To recap, it _______. The problem is that it only works without a warning if it's the sole expression in an if statement. If you use it in any other context, you get a warning:

    @available does not guard availability here; use if (@available) instead

As an example, all of the snippets below produce the warning:

    if (@available(iOS 12.1, *) && otherCondition) { … }
    
    if (!@available(iOS 13, *)) {
        // Code to run without iOS 13
    }
    
    return @available(iOS 11, *);

But these are all ways I would expect anyone to try to use this feature once told about it. The presence of this warning causes developers to work around it in convoluted ways that produce less concise, less readable code, often by nesting if statements or leaving the if empty in an if-else statement:

    if (@available(iOS 12.1, *)) {
        if (otherCondition) { … }
    }
    
    // Alternatively... second condition
    if (@available(iOS 12.1, *)) if (otherCondition) {
        …
    }
    
    if (@available(iOS 13, *)) { // Nothing }
    else {
        // Code to run without iOS 13
    }
    
    if (@available(iOS 11, *)) {
        return YES;
    } else {
        return NO;
    }

So, I guess I have two questions:

1) What is the scope/purpose of/reasoning behind the warning?
2) Assuming the warning serves a meaningful purpose for the examples above, what is that purpose?

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: "Unsupported Availability Guard" Warning

Tom Stellard via cfe-dev
> To recap, it _______.

Whoops, I forgot to fill in the blank. To recap, it allows you to guard a block of code to at least a certain OS version so that it won't emit "unguarded availability" warnings if you use APIs that are only available on that OS version.

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev