Re: [Boost-bugs] [Boost C++ Libraries] #5475: [Foreach] rvalue reference binding of temporary ranges

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5475: [Foreach] rvalue reference binding of temporary ranges
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-11-08 20:47:08


#5475: [Foreach] rvalue reference binding of temporary ranges
--------------------------------------+-------------------------------------
  Reporter: mimomorin@… | Owner: eric_niebler
      Type: Patches | Status: reopened
 Milestone: To Be Determined | Component: foreach
   Version: Boost Development Trunk | Severity: Problem
Resolution: | Keywords: foreach, C++0x
--------------------------------------+-------------------------------------

Comment (by Michel Morin <mimomorin@…>):

 Finally, I came up with workarounds for gcc's auto type deduction bugs.
 Now BOOST_FOREACH consists of three implementations:
 C++03 BOOST_FOREACH, C++11 BOOST_FOREACH and workarounds for gcc bugs.
 All the existing tests and new tests (involving function templates and
 C++11 lambdas)
 ran successfully on gcc and clang.

 To workaround gcc bugs, I used a hybrid of C++11 and C++03 codes:
 1. Bind a const reference to a range using `auto const&`. If the range is
 non-const lvalue, constness of the reference is stripped off via
 `const_cast` when accessing the reference.
 2. `begin` and `end` iterators are stored as `auto_any_t` to avoid the
 bugs.
 This workaround code is enabled in C++11 modes of gcc 4.4-4.6.

 On MSVC++ 10, I changed to use the C++03 BOOST_FOREACH code.
 Since this compiler doesn't support iteration over noncopyable rvalue
 ranges,
 it's not worth taking a risk for regressions.

 I also added a few tests:
 * noncopyable_rvalue_*.cpp: This test emits expected-failures if
 `BOOST_FOREACH_USE_CXX11` or `BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND` is
 not defined.
 * cxx11_gcc_workaround_*.cpp: This test needs support of rvalue
 references. On compilers without rvalue reference support, this test
 succeeds unconditionally.
 * cxx11_lambda_*.cpp: This test needs support of C++11 lambdas. On
 compilers without C++11 lambdas support, this test succeeds
 unconditionally.
 * char_array_fail_*.cpp: A test case that should fail to compile
 (`compile-fail` is specified in Jamfile). This test tries to iterating
 over a char array.
 * rvalue_nonconst_access_fail_*.cpp: A test case that should fail to
 compile (`compile-fail` is specified in Jamfile). This test tries to
 capture elements in an rvalue range by non-const references.

 Patches for `boost/foreach.hpp` and `libs/foreach/test/` are attached.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5475#comment:34>
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:07 UTC