Skip to content

[clang-tidy] False positive bugprone-use-after-move with std::tie #136105

Open
@dmpolukhin

Description

@dmpolukhin

Minimal reproducer https://godbolt.org/z/PoboWj4PM:

#include <tuple>
#include <utility>
#include <string>

std::pair<std::string, std::string> foo(std::string a, std::string b) {
  return std::make_pair(std::move(a), std::move(b));
}

void bar(std::string a, std::string b) {
  std::tie(a, b) = foo(std::move(a), std::move(b));
  std::tie(a, b) = foo(std::move(a), std::move(b));
}

/**
test.cpp:11:34: warning: 'a' used after it was moved [bugprone-use-after-move]
   11 |   std::tie(a, b) = foo(std::move(a), std::move(b));
      |                                  ^
test.cpp:10:24: note: move occurred here
   10 |   std::tie(a, b) = foo(std::move(a), std::move(b));
      |                        ^
test.cpp:11:48: warning: 'b' used after it was moved [bugprone-use-after-move]
   11 |   std::tie(a, b) = foo(std::move(a), std::move(b));
      |                                                ^
test.cpp:10:38: note: move occurred here
   10 |   std::tie(a, b) = foo(std::move(a), std::move(b));
      |                                      ^
**/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions