public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/10832: spurious compiler errors for definition of explicit specialisation of template member function of explicitly specialised class
@ 2003-05-17  7:36 gprentice
  0 siblings, 0 replies; only message in thread
From: gprentice @ 2003-05-17  7:36 UTC (permalink / raw)
  To: gcc-gnats


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-17  7:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-17  7:36 c++/10832: spurious compiler errors for definition of explicit specialisation of template member function of explicitly specialised class gprentice

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).