Binding a reference to the result of a conversion function

Rani Sharoni rani_sharoni@hotmail.com
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

<output>
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,
   int)':
defect.cpp:4: `B::operator B&()' is private
defect.cpp:7: within this context
</output>

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 
misleading.

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

Rani


_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



More information about the Gcc-bugs mailing list