11

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?

6
  • I have no problems with gcc 6.2.1 and your code. Commented Sep 23, 2016 at 8:43
  • gcc dev team, all your bugware are belong to us Commented Sep 23, 2016 at 8:44
  • gcc 6.1.1 has no problem as well Commented Sep 23, 2016 at 8:48
  • GCC 5.4.0, can reproduce, so apparently it's been fixed after 6.1? Commented Sep 23, 2016 at 8:49
  • Wait, how is foo even visible there? Isn't this a non-capturing lambda? Commented Sep 23, 2016 at 11:13

1 Answer 1

1

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.