c++/6808: G++ doesn't recognize templated reference conversion operators
squell@tfz.net
squell@tfz.net
Fri May 24 18:56:00 GMT 2002
>Number: 6808
>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:
More information about the Gcc-bugs
mailing list