This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/10832: spurious compiler errors for definition of explicit specialisation of template member function of explicitly specialised class
- From: gprentice at paradise dot net dot nz
- To: gcc-gnats at gcc dot gnu dot org
- Date: 17 May 2003 07:30:55 -0000
- Subject: c++/10832: spurious compiler errors for definition of explicit specialisation of template member function of explicitly specialised class
- Reply-to: gprentice at paradise dot net dot nz
>Number: 10832
>Category: c++
>Synopsis: spurious compiler errors for definition of explicit specialisation of template member function of explicitly specialised class
>Confidential: no
>Severity: critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Sat May 17 07:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Graeme Prentice
>Release: GNU CPP version 3.2 (mingw special 20020817-1) (cpplib) (80386, BSD syntax) / also 3.2.3
>Organization:
>Environment:
Windows XP pro
>Description:
The following error messages are reported. C++ standard 14.7.3 para 5 describes out of class definition of non template member of an explicit specialisation of a template class does not have the "template <>" prefix but doesn't mention how to define an explicit specialisation of a template member function of such a class. Comeau and Borland compile the code without error.
test1.cpp:14: wrong number of template arguments (1, should be 2)
test1.cpp:3: provided for `template<class DT, class ST> struct static_cast4'
test1.cpp:14: ISO C++ forbids declaration of `type name' with no type
test1.cpp:14: abstract declarator `int (static_cast4<int, long int>::)(long
int)' used as declaration
test1.cpp:14: no member function `$_0' declared in `static_cast4<int, long int>
'
test1.cpp:14: syntax error before `:' token
>How-To-Repeat:
template <typename DT, typename ST>
struct static_cast4;
template <>
struct static_cast4<int, long>
{
long h;
template <typename T>
static_cast4(T);
};
template <>
static_cast4<int,long>::static_cast4<long>(long v):h(v){}
int main()
{
static_cast4<int,long> o1(12L);
}
>Fix:
Use a non template member function instead of the explicit specialisation. I suspect this is not a full workaround because when the member function is referred to with angle brackets appended e.g. somefunction<...> then the compiler can't select the non template function.
template <typename DT, typename ST>
struct static_cast4;
template <>
struct static_cast4<int, long>
{
long h;
template <typename T>
static_cast4(T);
// workaround - non template member
static_cast4(long v):h(v){}
};
template <typename T>
static_cast4<int,long>::static_cast4(T v):h(v){}
int main()
{
static_cast4<int,long> o1(12L);
}
>Release-Note:
>Audit-Trail:
>Unformatted: