Skip to content

Question about the warning option for the clang #114125

@i80287

Description

@i80287

Compilation of the following code produces 2 warnings about potential null pointer dereference and null pointer dereference when compiled by the gcc with flags -O2 -Wnull-dereference.
This code contains ub and compiler is not obligated to warn about it, but is it possible to add additional warning option to the clang so that it reports about possible null pointer dereference like gcc does?

#include <cstdint>
#include <vector>

auto f(std::uint32_t n) {
    std::vector<std::int32_t> v(n + 1);
    v[0] = 1;
    return v;
}

int main() {
    f(static_cast<std::uint32_t>(-1));
}

On the godbolt
https://godbolt.org/z/4q4bqcx5G

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerduplicateResolved as duplicatequestionA 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