clang-tidy - cppcoreguidelines-missing-std-forward — Extra Clang Tools 22.1.6 documentation

# Extra Clang Tools 22.1.6 documentation

## clang-tidy - cppcoreguidelines-missing-std-forward

# cppcoreguidelines-missing-std-forward

Warns when a forwarding reference parameter is not forwarded inside the function body.

Example:

    template <class T>
    void wrapper(T&& t) {
      impl(std::forward<T>(t), 1, 2); // Correct
    }

    template <class T>
    void wrapper2(T&& t) {
      impl(t, 1, 2); // Oops - should use std::forward<T>(t)
    }

    template <class T>
    void wrapper3(T&& t) {
      impl(std::move(t), 1, 2); // Also buggy - should use std::forward<T>(t)
    }

    template <class F>
    void wrapper_function(F&& f) {
      std::forward<F>(f)(1, 2); // Correct
    }

    template <class F>
    void wrapper_function2(F&& f) {
      f(1, 2); // Incorrect - may not invoke the desired qualified function operator
    }

## Options

ForwardFunction

  Specify the function used for forwarding. Default is ::std::forward.

This check implements F.19 from the C++ Core Guidelines.