This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9489: gcc fails to find implicit conversion with template class
- From: jrestemeier at currantbun dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 28 Jan 2003 21:37:12 -0000
- Subject: c++/9489: gcc fails to find implicit conversion with template class
- Reply-to: jrestemeier at currantbun dot com
>Number: 9489
>Category: c++
>Synopsis: gcc fails to find implicit conversion with template class
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jan 28 21:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: jrestemeier@currantbun.com
>Release: Apple Computer, Inc. GCC version 1151, based on gcc version 3.1 20020420 (prerelease)
>Organization:
>Environment:
MacOS/X
>Description:
template<class T> class foo {
public:
T a, b;
foo & operator+=(const foo &rhs) {
a+=rhs.a;
b+=rhs.b;
return *this;
}
friend foo operator+(const foo &lhs, const foo &rhs) {
return foo(lhs)+=rhs;
}
};
template<class T>class bar {
public:
T ping, pong;
bar() {}
bar(const foo<T> & f) {
ping = f.a;
pong = f.b;
}
bar(int a, int b) {
ping = a;
pong = b;
}
operator foo<T>() const {
foo<T> f;
f.a = ping;
f.b = pong;
return f;
}
};
int main (int argc, const char * argv[]) {
// foo<int> f;
bar<int> a(1,2), b(3,4), c;
c=a+b;
return 0;
}
---
This fails with :
main.cpp: In function `int main(int, const char**)':
main.cpp:37: no match for `bar<int>& + bar<int>&' operator
remove the comment in front of "foo<int> f" and it compiles with just a warning about f beeing unused.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: