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

            Bug ID: 64791
           Summary: Generic lambda fails to implicitly capture `const`
                    variable
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at kera dot name

>From http://stackoverflow.com/q/28141403/560648

Reproduction:

/////////////////////////////
#include <iostream>
#include <functional>

int main()
{
    const int a = 2;
    std::function<void(int)> f = [&](auto b) { std::cout << a << ", " << b <<
std::endl; };
    f(3);
}
/////////////////////////////


Taking any of the following steps allows the program to build and run with the
expected output "2, 3":

- remove `const` from declaration of a
- name `a` in the capture-list instead of relying on implicit capture
- change declaration of `f` from `std::function<void(int)>` to `auto`
- make the lambda non-generic by changing `auto b` to `int b`
- use Clang (e.g. v3.5.0)

Suspect detection of odr-use is breaking, or this could be related to bug
61814, or something else entirely?

Reply via email to