[Boost-bugs] [Boost C++ Libraries] #1652: foreach + this keyword -> fails under MSVC

Subject: [Boost-bugs] [Boost C++ Libraries] #1652: foreach + this keyword -> fails under MSVC
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-02-23 20:04:52


#1652: foreach + this keyword -> fails under MSVC
----------------------------------------+-----------------------------------
 Reporter: archimed7592+svc_at_[hidden] | Owner: eric_niebler
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: foreach
  Version: Boost 1.34.1 | Severity: Problem
 Keywords: |
----------------------------------------+-----------------------------------
 ==== 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)

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1652>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC