Hello,
The following code fails to compile with gcc 4.5 or 4.6:
#include
template <typename>
void f()
{
int A[6];
BOOST_FOREACH(auto&& x, A)
;
}
void g()
{
f<int>();
}
The error is:
test.cpp: In function 'void f() [with <template-parameter-1-1> = int]':
test.cpp:14:12: instantiated from here
test.cpp:6:5: error: invalid initialization of reference of type 'int&&' from expression of type 'int'
Interestingly, the error goes away if I make f() a non-template function. It also compiles fine with gcc 4.4.
The native range-based for version, however, compiles fine with gcc 4.6 (which is the only version to support it):
#include
template <typename>
void f()
{
int A[6];
for(auto&& x : A)
;
}
void g()
{
f<int>();
}
What is going on here? Is this a Boost issue or a gcc issue?
Thanks,
Nate.