[cfe-dev] "Unsupported Availability Guard" Warning

Tanner Bennett via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 25 14:39:55 PST 2019


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191125/4da03714/attachment.html>


More information about the cfe-dev mailing list