id summary reporter owner description type status milestone component version severity resolution keywords cc 1652 foreach + this keyword -> fails under MSVC archimed7592+svc@… Eric Niebler "==== Summary ==== When using ''this'' keyword in second argument of ''foreach''(in any form) something goes wrong(unintelligible compiler errors like ""cannot use keyword ''this'' in static or non member function""). Looks like MSVC bug, but, AFAIK, Boost tries to workaround such bugs. ==== Example ==== {{{ struct A { const std::vector< int > &vector() { struct { const std::vector< int > operator ()() const { std::vector< int > result; result.push_back(1); result.push_back(10); result.push_back(20); result.push_back(50); return result; } } init; static const std::vector< int > result = init(); return result; } void test() { foreach(const int &i, this->vector()) std::cout << i << std::endl; } }; }}} Fails w/ these error messages: {{{ Compiling... test.cpp test.cpp(35) : error C2355: 'this' : can only be referenced inside non-static member functions test.cpp(35) : error C2227: left of '->vector' must point to class/struct/union/generic type test.cpp(35) : error C2355: 'this' : can only be referenced inside non-static member functions test.cpp(35) : error C2227: left of '->vector' must point to class/struct/union/generic type [... and so on ...] }}} OTOH, these two examples compiles (and works) fine: {{{ void test() { foreach(const int &i, vector()) std::cout << i << std::endl; } }}} {{{ void test() { const std::vector< int > &vector = this->vector(); foreach(const int &i, vector) std::cout << i << std::endl; } }}} ==== Info ==== * Boost version: 1.34.1 * MSVC version: 8.0-SP1([http://lists.boost.org/Archives/boost/2006/04/103992.php here] 7.1 and 8.0 are reported)" Bugs closed To Be Determined foreach Boost 1.34.1 Problem fixed