Arcoth/Constainer

StableVector - access to temporary whose lifetime has ended

Closed this issue · 2 comments

This issue occurs in e.g. the following scenario:

constexpr auto f() {return StableVector<int, ChunkPool<int, 10>>{1};}
static_assert( f()[0] );

Clang's error message:

….cxx:4:16: error: static_assert expression is not an integral constant expression
static_assert( f()[0] );
               ^~~~~~
….cxx:4:16: note: read of temporary whose lifetime has ended
….cxx:3:28: note: temporary created here
constexpr auto f() {return StableVector<int, ChunkPool<int, 10>>{1};}
                           ^

Whether this is a bug or not isn't entirely clear, but the former is probably the case, as e.g. AddressSanitizer doesn't show anything.

Reproducing:

struct A {
    int j=1, *i=&j;
    constexpr A() = default;
    constexpr A(A&& a) : j(a.j) {}
};

constexpr auto f() {return A{};}

constexpr auto obj = *f().i;

Reported as #24597.

Fixed in trunk 246282.