Skip to content

extend returns_nonnull function attribute diagnostics #106392

@firewave

Description

@firewave
__attribute__((returns_nonnull)) void* func();

static void f1()
{
    if (func()) {} // warning
}

static void f2()
{
    void* p = func();
    if (p) {} // no warning
}
<source>:5:9: warning: nonnull function call 'func()' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion]
    5 |     if (func()) {} // warning
      |     ~~  ^~~~~~
<source>:1:16: note: declared 'returns_nonnull' here
    1 | __attribute__((returns_nonnull)) void* func();
      |  

https://godbolt.org/z/x3r5oP6db

I guess this is out of scope of the existing warning and would require a clang-tidy or static analyzer check instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions