Skip to content

cppcoreguidelines-missing-std-forward should consider std::forward usage in lambda capture also with uniform initialization #150446

@mous16

Description

@mous16

Following the issue #68105, I found out that clang-tidy still complains about forwarding in lambda capture, if lambda variable is initialized with braces instead of equal.

Example:

#include <utility>

template <typename F>
auto makeFuncA(F&& func) {
    return [func2 = std::forward<F>(func)]() { func2(); };
}

template <typename F>
auto makeFuncB(F&& func) {
    return [func2{std::forward<F>(func)}]() { func2(); };
}

int main() {
    auto a{makeFuncA([]() {})};
    a();
    auto b{makeFuncB([]() {})};
    b();
}

clang-tidy is ok with makeFuncA, while complains on makeFuncB.
func2{std::forward<F>(func)} should be considered the same of func2 = std::forward<F>(func).

Live example: https://godbolt.org/z/barb17xM7

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