Skip to content

bugprone-use-after-move not reported for usage after std::move() with range #137156

Open
@firewave

Description

@firewave
#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include <string>

int main()
{
    std::list<std::string> l1 = { "1" };

    std::list<std::string> l2;
    std::move(l1.begin(), l1.end(), std::back_inserter(l2));

    std::cout << "l1: " << *l1.cbegin() << '\n';
    std::cout << "l2: " << *l2.cbegin() << '\n';
}

https://godbolt.org/z/Y96a6nv7h

https://en.cppreference.com/w/cpp/algorithm/move

Also not detected by the Clang Static Analyzer clang-analyzer-cplusplus.Move check: #137157.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions