`-Wunguarded-availability` misses diagnostics in default member initializers and ignores field annotations as suppressing context
- 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
Assessment
This issue has not been assessed yet.