https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62082

            Bug ID: 62082
           Summary: cout fails to work with auto variable initialized with
                    curvy brackets
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aleksej.penkov at hotmail dot com

This simple code (compiled with -std=c++11 -Wall):
#include <iostream>

int main()
{
    double d = 5.5;
    auto a {d};

    std::cout<<d<<' '<<a<<std::endl;
}

gives this compilation error:
2.cpp: In function ‘int main()’:
2.cpp:8:14: error: cannot bind ‘std::basic_ostream<char>’ lvalue to
‘std::basic_ostream<char>&&’
  std::cout<<d<<' '<<a<<std::endl;
              ^
In file included from /usr/local/include/c++/4.9.1/iostream:39:0,
                 from 2.cpp:1:
/usr/local/include/c++/4.9.1/ostream:602:5: note: initializing argument 1 of
‘std::basic_ostream<_CharT, _Traits>&
std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT
= char; _Traits = std::char_traits<char>; _Tp = std::initializer_list<double>]’
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
     ^

If i replace
auto a {d};
with
auto a = d;

it works fine.

Reply via email to