llvm / llvm/llvm-project

`-Wunguarded-availability` misses diagnostics in default member initializers and ignores field annotations as suppressing context

Open
#194,708 0 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics false-negative false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`-Wunguarded-availability-new` does not properly handle default member initializers. There are two sub-problems:

## No availability checking in default member initializers
Calling a function with an availability attribute in a default member initializer produces no warning, whether the call is bare, inside a lambda, or inside a block:

```
// -triple x86_64-apple-macosx10.9.0
__attribute__((availability(macos, introduced = 11.0))) int init11();
__attribute__((availability(macos, introduced = 13.0))) int init13();

struct S1 {
int x = init11(); // no warning — should warn
};

struct S2 {
// Field annotated with 11.0, but callee requires 13.0 — should warn
int x __attribute__((availability(macos, introduced = 11.0))) = init13(); // no warning
};

struct S3 {
int x = [](){ return init11(); }(); // no warning — should warn
};

struct S4 {
int x = ^(){ return init11(); }(); // no warning — should warn
};
```

## Field annotations not respected as suppressing context in local structs
Inside a function body, methods and statement-expression default member initializers of local structs are checked via the enclosing function's scope. But annotations on the field or method itself are not consulted, producing false positives:

```
void test() {
struct S5 {
// Field annotation should suppress — but warns
int x __attribute__((availability(macos, introduced = 11.0))) = ({ init11(); });
};

struct S6 {
// Method annotation should suppress — but warns
__attribute__((availability(macos, introduced = 11.0))) void method() {
init11();
}
};
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.