Skip to content

[clang-tidy] bugprone-use-after-move false positive with forwarding class member #236015

Description

@ixSci

The following code:

#include <utility>
struct Obj
{
    int a;
    int b;
};

void binaryF(int a, int b)
{}

template<typename... Args>
void fun(Args&&... args)
{
    (binaryF(args.a, std::forward<Args>(args).b), ...);
}

void f()
{
    fun(Obj{1, 2}, Obj{3, 4});
}

Would trigger bugprone-use-after-move because the check thinks that args is used after being forwarded. But it is not it is never forwarded (consumed), only its member is so using args.a is perfectly safe. Godbolt: https://godbolt.org/z/efMKEoE47

Activity

  1. llvmorg-github-actions commented on Oct 27, 2026

    @llvmorg-github-actions

    @llvm/issue-subscribers-clang-tidy

    Author: Evgeniy Shcherbina (ixSci)

    Details The following code: ```cpp #include <utility> struct Obj { int a; int b; };

    void binaryF(int a, int b)
    {}

    template<typename... Args>
    void fun(Args&&... args)
    {
    (binaryF(args.a, std::forward<Args>(args).b), ...);
    }

    void f()
    {
    fun(Obj{1, 2}, Obj{3, 4});
    }

    Would trigger bugprone-use-after-move because the check thinks that `args` is used after being forwarded. But it is not it is never forwarded (consumed), only its member is so using `args.a` is perfectly safe. Godbolt: https://godbolt.org/z/efMKEoE47
    </details>
    
  2. yashaggarwal85d commented on Oct 27, 2026

    @yashaggarwal85d
    Contributor

    Raised a PR for a potential fix for this issue. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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