https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82611

            Bug ID: 82611
           Summary: Incorrect warning for redundant capture in lambda
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jetanner at usc dot edu
  Target Milestone: ---

test.cpp:
int main()
{
    int i;
    auto a = [=, i](){};
}

Warning produced:
test.cpp: In function ‘int main()’:
test.cpp:4:15: warning: explicit by-copy capture of ‘i’ redundant with by-copy
capture default
  auto a = [=, i](){};

variable i is not captured with the '=' because i is not used inside the
lambda, so capturing it explicitly is necessary. However, gcc still reports a
redundant capture.

My use-case is that I capture a std::shared_ptr to prevent it from going out of
scope and deconstructing, even though it is not used directly inside my lambda.

Reply via email to