https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86018
Bug ID: 86018 Summary: Incorrect unused warning for int passed by reference to lambda Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rconde01 at hotmail dot com Target Milestone: --- https://godbolt.org/g/XLjyWM When compiled with: -std=c++14 -Wall -Wextra #include <string> typedef void(*TheFP)(int & e); class MyObject { public: void DoSomething(TheFP) { } }; void myFunc() { MyObject m; m.DoSomething ( [](auto i) { i = 5; } ); } ---------------------------------------------------------------------------- gives: In instantiation of 'myFunc()::<lambda(auto:1)> [with auto:1 = int]': 19:18: required by substitution of 'template<class auto:1> myFunc()::<lambda(auto:1)>::operator decltype (((const myFunc()::<lambda(auto:1)>*)((const myFunc()::<lambda(auto:1)>* const)0))->operator()(static_cast<auto:1&&>(<anonymous>))) (*)(auto:1)() const [with auto:1 = int&]' 23:5: required from here 19:17: warning: parameter 'i' set but not used [-Wunused-but-set-parameter] [](auto i) ~~~~~^ ---------------------------------------------------------------------------- The workaround is to change it to: void myFunc() { MyObject m; m.DoSomething ( [](auto & i) { i = 5; } ); }