Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5475: [Foreach] rvalue reference binding of temporary ranges
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-10-17 15:17:34
#5475: [Foreach] rvalue reference binding of temporary ranges
--------------------------------------+-------------------------------------
Reporter: mimomorin@⦠| Owner: eric_niebler
Type: Patches | Status: closed
Milestone: To Be Determined | Component: foreach
Version: Boost Development Trunk | Severity: Problem
Resolution: fixed | Keywords: foreach, C++0x
--------------------------------------+-------------------------------------
Comment (by Michel Morin <mimomorin@â¦>):
On gcc-4.3 (C++11), I found a regression that was not caught by the test.
Due to auto type deduction bugs (`decltype`) in template functions,
the following code does not compile on gcc-4.3 (C++11) with Boost trunk
{{{
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
template<typename T>
typename boost::mpl::if_<boost::is_rvalue_reference<T&&>, T const,
T>::type
add_const_if_rvalue(T&& t)
{
return t;
}
template <typename T>
void f()
{
BOOST_FOREACH(int const& i, add_const_if_rvalue(std::vector<int>(3,
0))) {
std::cout << i << std::endl;
}
}
int main (int argc, char* argv[])
{
f<void>();
return 0;
}
}}}
This code compiles fine on gcc-4.3 (C++11) with Boost.1.47.
It also compiles fine on gcc-4.5, 4.6, 4.7 (C++11) with Boost trunk.
Do we need to revert to the C++03 BOOST_FOREACH on gcc-4.3 too?
Patch is pretty simple.
{{{
#!diff
Index: boost/foreach.hpp
===================================================================
--- boost/foreach.hpp (revision 75012)
+++ boost/foreach.hpp (working copy)
@@ -34,7 +34,7 @@
// With these C++0x features, temporary collections can be bound to
// rvalue references and their lifetime is extended. No copy/move is
needed.
#if !defined(BOOST_NO_DECLTYPE) && !defined(BOOST_NO_RVALUE_REFERENCES)
\
- && !(BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ == 4) &&
!defined(BOOST_INTEL) && \
+ && !(BOOST_WORKAROUND(__GNUC__, == 4) && (__GNUC_MINOR__ <= 4) &&
!defined(BOOST_INTEL) && \
!defined(BOOST_CLANG))
# define BOOST_FOREACH_USE_RVALUE_REFERENCE_BINDING
// Some compilers let us detect even const-qualified rvalues at compile-
time
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5475#comment:29> 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