[Bug c++/58713] New: error: cannot bind ‘std?=::ostream {aka std::basic ostream<char>=?UTF-8?Q?}’ lvalue to ‘std?=::basic ostream<char>=?UTF-8?Q?&&’

ali.baharev at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Oct 13 12:20:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58713

            Bug ID: 58713
           Summary: error: cannot bind ‘std::ostream {aka
                    std::basic_ostream<char>}’ lvalue to
                    ‘std::basic_ostream<char>&&’
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ali.baharev at gmail dot com

#include <iostream>

struct A { };

int main() {
    A a;
    std::cout << a;
}
-----

g++ 4.8.1, 64 bit with -std=c++11 gives the correct error message:

main.cpp:7:15: error: no match for ‘operator<<’ (operand types are
‘std::ostream {aka std::basic_ostream<char>}’ and ‘A’)
     std::cout << a;
               ^

However, 4.8.1, 32 bit or 4.7.2, 64 bit gives:

prog.cpp:7:18: error: cannot bind ‘std::ostream {aka std::basic_ostream<char>}’
lvalue to ‘std::basic_ostream<char>&&’
     std::cout << a;
                  ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:602:5: error:   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 = A]’
     operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
     ^

Could this rather confusing error message be improved?

Why do the 32 and 64 bit versions behave differently?


More information about the Gcc-bugs mailing list