This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/6807: G++ doesn't recognize templated reference conversion operators



>Number:         6807
>Category:       c++
>Synopsis:       G++ doesn't recognize templated reference conversion operators
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Fri May 24 18:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     squell@tfz.net
>Release:        g++ 3.1.0
>Organization:
>Environment:
Reading specs from c:/djgpp/lib/gcc-lib/djgpp/3.1/specs
Configured with: ../configure i586-pc-msdosdjgpp --prefix=/dev/env/DJDIR --disable-nls
Thread model: single
gcc version 3.1
>Description:
The code below should be pretty clear.
Note that even though line 16 does not give a diagnostic, the conversion operator defined still doesn't get called, so a hard typecast is performed, which is not what is wanted.

It's interesting to see that if the class "blaat" is instead equipped with a non-template "operator int&()" member, the only line which is rejected by the compiler is line 13. :)

At the very least, this does not comply with 14.5.2/4.

test.cpp: In function `int main()':
test.cpp:12: cannot convert `blaat' to `int' in initialization
test.cpp:14: no matching function for call to `blaat::operator int&()'
test.cpp:15: `struct blaat' used where a `int' was expected
test.cpp:17: could not convert `H' to `int&'
test.cpp:7: in passing argument 1 of `void foo(int&)'
>How-To-Repeat:
struct blaat {
    template<class T> operator T&()
    {
    }
};

void foo(int&) { }

int main()
{
    blaat H;
    int a = H;
    int b = H.operator int();   // this is ok ??
    int c = H.operator int&();
    int d = (int)H;
    int e = (int&)H;            // conversion isn't called
    foo(H);
}

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]