vendredi 23 septembre 2016

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?

Aucun commentaire:

Enregistrer un commentaire