This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/86018] New: Incorrect unused warning for int passed by reference to lambda
- From: "rconde01 at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 31 May 2018 17:56:45 +0000
- Subject: [Bug c++/86018] New: Incorrect unused warning for int passed by reference to lambda
- Auto-submitted: auto-generated
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;
}
);
}