Skip to content

Detect use-after-moveΒ #163597

@usx95

Description

@usx95
#include <iostream>
#include <memory>

struct A {
    std::string data;
};

std::unique_ptr<A> bar();

void take(std::unique_ptr<A> in);

int main() {
    std::unique_ptr<A> a = bar();
    A* pointer = a.get();
    take(std::move(a));
    std::cout << pointer->data; // use-after-move!
}

https://godbolt.org/z/sbdGGqKEx
More examples: https://godbolt.org/z/8WKsMEodo

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions