Issue 155841
Summary `_Nullable` annotations don't trigger `clang-analyzer-core.CallAndMessage` diagnostics
Labels new issue
Assignees
Reporter jmcclellan-figma
    In the following file

```
struct A {
 void doSomething();
};

struct B {
    A* _Nullable a();
};

int main() {
    const auto a = B{}.a();
    // un-comment this line to get the clang-analyzer-core.CallAndMessage lint.
    // I'm wondering why this line is needed, since we mark it as nullable already!
    // [[maybe_unused]] int x = a ? 1 : 0;
    a->doSomething();
    return 0;
}```

If you run `clang-tidy --checks="clang-analyzer-core*" file.cpp`, you won't get a `clang-analyzer-core.CallAndMessage` diagnostic until you comment out the line that checks `a` against null.  I think it would be useful and in the spirit of the [nullability annotations](https://clang.llvm.org/docs/analyzer/developer-docs/nullability.html) to instead issue a diagnostic here, because the return value of `a()` is explicitly marked nullable.  [godbolt short link for repro](https://godbolt.org/z/Ps165aKa7)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to