[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/86018] New: Incorrect unused warning for int passed by reference to lambda
From:       "rconde01 at hotmail dot com" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2018-05-31 17:56:45
Message-ID: bug-86018-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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; 
        }
    );
}=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic