Skip to content

_Nullable annotations don't trigger clang-analyzer-core.CallAndMessage diagnostics #155841

@jmcclellan-figma

Description

@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 to instead issue a diagnostic here, because the return value of a() is explicitly marked nullable. godbolt short link for repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:static analyzerquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions