Skip to content

[LifetimeSafety] False-positive when paths are moved to a longer-lived storage #167290

@usx95

Description

@usx95
#include <stdint.h>

#include <span>
#include <utility>
#include <vector>

void foo() {
    std::vector<int> src_data;
    std::span<int> src_span;
    {
        std::vector<int> temp_src_data = {1, 2, 3};
        temp_src_data.push_back(12);

        src_span = temp_src_data;
//                 ^~~~~~~~~~~~~

        src_data = std::move(temp_src_data);
    }
//  ^ destroyed here

    (void)src_span[0];
//        ^~~~~~~~ note: later used here
}

https://godbolt.org/z/74WzPPnT1

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)false-positiveWarning fires when it should not

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions