Skip to content

-Wall gives spurious "is not used" warning when expanding variadic capture and other pack #112132

@Aster89

Description

@Aster89

(Maybe related to #40556.)

(Complete repro steps.)

auto foo(auto ...x) {
    return [...x = x](auto ...f) {
        (f(x), ...);
    };
}

int main() {
    foo(0)([](auto x){ return x; });
}

Compiling the code above via

clang++ -std=c++20 -Wall file.cpp

produces this spurious warning:

file.cpp:2:16: warning: lambda capture 'x' is not used [-Wunused-lambda-capture]
    2 |     return [...x = x](auto ...f) {
      |                ^
file.cpp:8:5: note: in instantiation of function template specialization 'foo<int>' requested here
    8 |     foo(0)([](auto x){ return x; });
      |     ^
1 warning generated.

$ clang++ --version
clang version 18.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang: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