Skip to content

Incorrect -Wunused-lambda-capture warning for this capture #36228

@hyp

Description

@hyp
Bugzilla Link 36880
Version trunk
OS All
CC @CaseyCarter,@elvenfighter,@rogerorr

Extended Description

$ cat test.cpp

template<class T>
struct DummyTemplate {
    template<class T2>
    void methodTemplate(const T2&){}

    void ToTemplate(const int& param){
        [this](const auto& p){methodTemplate(p);}(param);
    }
};

int main()
{
    int i{};
    DummyTemplate<bool> dt;
    dt.ToTemplate(i);
}
$ clang test.cpp -std=c++14 -Wunused-lambda-capture
test.cpp:7:10: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
        [this](const auto& p){methodTemplate(p);}(param);
         ^
test.cpp:15:8: note: in instantiation of member function 'DummyTemplate<bool>::ToTemplate' requested here
    dt.ToTemplate(i);
       ^
1 warning generated.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyfalse-positiveWarning fires when it should notlambdaC++11 lambda expressions

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions