Bug 23764 - Implicit conversion to a reference for an object broken
Summary: Implicit conversion to a reference for an object broken
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-07 15:39 UTC by Richard Lyle
Modified: 2005-09-07 15:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Lyle 2005-09-07 15:39:14 UTC
Trying to compile the following code on a FreeBSD 5.4 machine, using GCC 
4.0.1.... 

# 1 "Test.cpp"
# 0 "<built-in>"
# 1 "<command line>"
# 1 "Test.cpp"

class OutStream
{
public:
 OutStream();
};

inline OutStream & operator<<( OutStream & output, const int & value )
{

 return output;
}

class Client
{
public:
 OutStream send()
 {
  return OutStream();
 }
};

int main(int argc,char **argv)
{
 Client myclient;

 int x = 32;
 int y = 64;

 myclient.send() << x << y;
 return 0;
}

Produces the following output...

Using built-in specs.
Target: i386-portbld-freebsd5.4
Configured with: ./..//gcc-4.1-20050730/configure --disable-nls --with-system-
zlib --with-libiconv-prefix=/usr/local --program-suffix=41 --
libdir=/usr/local/lib/gcc/i386-portbld-freebsd5.4/4.1.0 --with-gxx-include-
dir=/usr/local/lib/gcc/i386-portbld-freebsd5.4/4.1.0/include/c++/ --disable-
shared --disable-rpath --prefix=/usr/local i386-portbld-freebsd5.4
Thread model: posix
gcc version 4.1.0 20050730 (experimental)
 /usr/local/libexec/gcc/i386-portbld-freebsd5.4/4.1.0/cc1plus -E -quiet -v 
Test.cpp -fpch-preprocess -o Test.ii
ignoring nonexistent directory "/usr/local/lib/gcc/i386-portbld-
freebsd5.4/4.1.0/gcc/i386-portbld-freebsd5.4/4.1.0/../../../../i386-portbld-
freebsd5.4/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/i386-portbld-freebsd5.4/4.1.0/include/c++/
 /usr/local/lib/gcc/i386-portbld-freebsd5.4/4.1.0/include/c++//i386-portbld-
freebsd5.4
 /usr/local/lib/gcc/i386-portbld-freebsd5.4/4.1.0/include/c++//backward
 /usr/local/include
 /usr/local/lib/gcc/i386-portbld-freebsd5.4/4.1.0/gcc/i386-portbld-
freebsd5.4/4.1.0/include
 /usr/include
End of search list.
 /usr/local/libexec/gcc/i386-portbld-freebsd5.4/4.1.0/cc1plus -fpreprocessed 
Test.ii -quiet -dumpbase Test.cpp -auxbase Test -version -o Test.s
GNU C++ version 4.1.0 20050730 (experimental) (i386-portbld-freebsd5.4)
        compiled by GNU C version 4.1.0 20050730 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: c62afa56bfea22d68bd8bf2d1f862a27
Test.cpp: In function 'int main(int, char**)':
Test.cpp:33: error: no match for 'operator<<' in 'myclient. Client::send() << 
x'
Test.cpp:11: note: candidates are: OutStream& operator<<(OutStream&, const 
int&)
Comment 1 Andrew Pinski 2005-09-07 15:49:38 UTC
Not a bug as you cannot bind a rvalue to the reference type.
Basicially what you have is:

int g(void);

void h(int&);

void j(void)
{
  h(g());
}

And that is invalid.  You can bind a rvalue to a const reference type though.