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++/9898: Template cast operator fo template class


>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:


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