Boost logo

Boost Users :

Subject: Re: [Boost-users] [foreach] gcc 4.5 & 4.6 compiler error with BOOST_FOREACH(auto&& ...) loop
From: Michel MORIN (mimomorin_at_[hidden])
Date: 2011-03-05 12:35:05


Michel MORIN wrote:
> I think this is a gcc bug.
> In a function template, auto deduction fails to deduce an lvalue reference
> when auto&& is initiliazed by a function return value of an lvalue reference.
>
> Minimal test case:
> (This code fails to be compiled.)
>
> int& identity(int& i)
> {
>    return i;
> }
>
> template <typename = void> // Commenting this out makes compilation succeed
> void f()
> {
>    int i = 0;
>    auto&& x = identity(i); // In a function template, auto deduction fails
> }
>
> int main (int argc, char* argv[])
> {
>    f();
>    return 0;
> }

This seems an unknown bug of gcc, so I reported this to GCC Bugzilla:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47999

Good thing you found this problem, Nate!

Regards,
Michel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net