Skip to content

-Wunused-lambda-capture too strict with variadic usage #40556

@JVApen

Description

@JVApen
Bugzilla Link 41211
Version 8.0
OS Windows NT
CC @zmodem,@JVApen,@pepsiman,@zygoloid,@Weverything

Extended Description

Reproduction on compiler explorer: https://godbolt.org/z/hJHQui
error: lambda capture 'i' is not used [-Werror,-Wunused-lambda-capture]

In the example below, we get a compiler warning on 'unused' lambda capture 'i'.
when changing the call to f from 'f<>' to 'f', the warning goes away.
When removing the capture, as suggested, we get: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default specified

t.cpp

template <typename ...T>
int h(T &&...t);

template
int g(int i);

template<typename ...T>
auto f(int i)
{
return i{ return h(g(i)...); };
}

int main()
{
return f<>(42)();
}

run.sh

clang++ -std=c++17 -O3 -Wunused-lambda-capture -Werror t.cpp

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++11clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions