C26800

warning C26800: Use of a moved from object: <lock>.

Warning C26800 is triggered when variable is used after it has been moved from. A variable is considered moved from after it was passed to a function as rvalue reference. There are some legitimate exceptions for uses such as assignment, destruction, and some state resetting functions such as std::vector::clear.

Examples

The following code will generate C26800.


#include <utility>

struct X {
    X();
    X(const X&);
    X(X&&);
    X &operator=(X&);
    X &operator=(X&&);
    ~X();
};

template<typename T>
void use_cref(const T&);

void test() {
    X x1;
    X x2 = std::move(x1);
    use_cref(x1);                // @expected(26800)
}

The following code will not generate C26800.


#include <utility>

struct MoveOnly {
    MoveOnly();
    MoveOnly(MoveOnly&) = delete;
    MoveOnly(MoveOnly&&);
    MoveOnly &operator=(MoveOnly&) = delete;
    MoveOnly &operator=(MoveOnly&&);
    ~MoveOnly();
};

template<typename T>
void use(T);

void test() {
    MoveOnly x;
    use(std::move(x)); // no 26800
}