This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9898: Template cast operator fo template class
- From: philippeb at videotron dot ca
- To: gcc-gnats at gcc dot gnu dot org
- Date: 2 Mar 2003 01:34:12 -0000
- Subject: c++/9898: Template cast operator fo template class
- Reply-to: philippeb at videotron dot ca
>Number: 9898
>Category: c++
>Synopsis: Template cast operator fo template class
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 02 01:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: gcc
>Release: 3.0.4
>Organization:
>Environment:
Debian Linux 2.2.19
>Description:
GCC cannot compile the following:
#include <iostream>
using namespace std;
template <typename T>
struct Wrapper
{
template <typename U>
operator Wrapper<U> const & ()
{
}
};
inline void foo(Wrapper<int> const &)
{
cout << __PRETTY_FUNCTION__ << endl;
}
int main()
{
foo(Wrapper<long>());
}
Ouputs:
templatetemplate.cpp: In function `int main()':
templatetemplate.cpp:25: could not convert `{}' to `const Wrapper<int>&'
templatetemplate.cpp:18: in passing argument 1 of `void foo(const Wrapper<int>&)'
>How-To-Repeat:
>Fix:
- Transform Wrapper<> into non-template class Wrapper.
- Remove the reference (&) returned by the cast operator.
- Overload the cast operator to return Wrapper<int> const &.
>Release-Note:
>Audit-Trail:
>Unformatted: