Re: [Boost-bugs] [Boost C++ Libraries] #6554: Compiler error dereferencing multi_array value via an iterator

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6554: Compiler error dereferencing multi_array value via an iterator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-04-11 20:55:26


#6554: Compiler error dereferencing multi_array value via an iterator
-------------------------------+--------------------------------------------
  Reporter: bill_buklis | Owner: garcia
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: multi_array
   Version: Boost 1.49.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+--------------------------------------------

Comment (by bill_buklis):

 I've figured out what the problem is:

 I'm not really sure why (perhaps for MWCW and BCC compatibility?), but
 operator-> for the iterator uses an indirect struct "operator_arrow_proxy"
 which takes a reference as the type. The operator_arrow_proxy struct then
 goes on to use a return type for operator-> that is T*. Since T is a
 reference and not a normal value_type, this is illegal, just as int&* is
 an illegal type. I modified the structure so that it properly returns a
 pointer.

 Old version:

 {{{
 template <class T>
 struct operator_arrow_proxy
 {
   operator_arrow_proxy(T const& px) : value_(px) {}
   T* operator->() const { return &value_; }
   // This function is needed for MWCW and BCC, which won't call operator->
   // again automatically per 13.3.1.2 para 8
   operator T*() const { return &value_; }
   mutable T value_;
 };
 }}}

 Updated code:

 {{{
 template <class T>
 struct operator_arrow_proxy
 {
         typedef typename remove_reference<T>::type* pointer;

   operator_arrow_proxy(T const& px) : value_(px) {}
   pointer operator->() const { return &value_; }
   // This function is needed for MWCW and BCC, which won't call operator->
   // again automatically per 13.3.1.2 para 8
   operator pointer() const { return &value_; }
   mutable T value_;
 };

 }}}

 The differences are the typedef for "pointer" using remove_reference and
 changing the return types from T* to pointer. I also added an include for
 "boost/type_traits/remove_reference.hpp".

 Note: This attached iterator.hpp is modified after the trunk version which
 includes fixes for the MSVC debug output_iterator issue (see ticket:4874).
 This fix is not currently in the boost release. So if you use the attached
 file, then make sure to use the rest of the files from the trunk version.
 The patch itself does not require the MSVC debug fix and may be applied to
 the release version.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6554#comment:1>
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:50:09 UTC