mgehre / llvm-project

The home of the clang-based implementation of lifetime safety warnings.
39 stars 4 forks source link

False positive with vector subscript operator #75

Closed marcomagdy closed 5 years ago

marcomagdy commented 5 years ago
#include <vector>

auto fun(std::vector<int>& v)
{
    v.push_back(42);
    return v[0];
}

gives:

<source>:6:12: error: dereferencing a dangling pointer [-Werror,-Wlifetime]

    return v[0];

           ^

<source>:5:5: note: modified here

    v.push_back(42);

    ^

see here https://godbolt.org/z/_jSmO9

I'm not sure if this is the same issue reported in #18 feel free to close it as a duplicate if that's the case.

Thanks for all your wok on this.

mgehre commented 5 years ago

I think it's a duplicate of #66, but let's verify once we fix it.

lklein53 commented 5 years ago

I checked the example with my PR that is trying to fix issue #66 and the provided example is also working with the changes.

lklein53 commented 5 years ago

This should also be fixed as part of the fix for issue #66 that got merged now.