Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is GCC doing to my static variable in a lambda?

Using GCC 6.1, the following program:

#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>

int main()
{
    static const std::string foo {"foo"};
    std::vector<std::string> bars {{""}};
    std::cout << "foo outside: " << foo << std::endl;
    std::for_each(std::cbegin(bars), std::cend(bars), [] (const auto& bar) {
        std::cout << "foo inside: " << foo << std::endl;
    });
}

Prints:

foo outside: foo
foo inside: 

Live On Coliru

What's going on?

like image 833
Daniel Avatar asked Sep 23 '16 08:09

Daniel


1 Answers

This bug is already filed as Bug 69078 and yet unconfirmed.

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

like image 177
Trevir Avatar answered Oct 31 '22 23:10

Trevir