Binding a reference to the result of a conversion function

Rani Sharoni
Sun Feb 9 16:51:00 GMT 2003

This is a standard C++ compliant issue.

The following well-formed code failed to complie with (Cygwin gcc version 
3.2 20020927 (prerelease)):

class B {
    operator B&();

const B& r = B();

gcc -c defect.c

defect.cpp:4: warning: conversion to a reference to the same type will never
   use a type conversion operator
defect.cpp:3: warning: all member functions in class `B' are private
defect.cpp: In function `void __static_initialization_and_destruction_0(int,
defect.cpp:4: `B::operator B&()' is private
defect.cpp:7: within this context

The first warning is correct.
The code is well-formed according to 12.3.2/1 although 8.5.3/5/1/2 is quite 

Another interesting case (no warning for it) is when the result of the 
conversion function is of type derived from B.


Add photos to your messages with MSN 8. Get 2 months FREE*.

More information about the Gcc-bugs mailing list