Skip to content

clang-tidy 14.0.6 gives a false-positive bugprone-use-after-move report in chained expressions #57758

Closed
@georgthegreat

Description

@georgthegreat

Consider the following code

#include <cassert>
#include <vector>

struct test {
 test& foo(std::vector<int> const& v) { assert(v.size() == 1); return *this; }
 int bar(std::vector<int> v ) { return v.size(); }
};

int main() {
    std::vector<int> v = { 42 };
    return test{}.foo(v).bar(std::move(v));

}

clang-tidy 14.0.6 reports the following error:

tidy14-bug/main.cpp:11:23: error: 'v' used after it was moved [bugprone-use-after-move,-warnings-as-errors]
    return test{}.foo(v).bar(std::move(v));
                      ^
tidy14-bug/main.cpp:11:30: note: move occurred here
    return test{}.foo(v).bar(std::move(v));
                             ^
tidy14-bug/main.cpp:11:23: note: the use and move are unsequenced, i.e. there is no guarantee about the order in which they are evaluated
    return test{}.foo(v).bar(std::move(v));
                      ^

The standard, however, clearly defines the behavior for the case.
This false-positive breaks a lot of code in our codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions