public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: gprentice@paradise.net.nz
To: gcc-gnats@gcc.gnu.org
Subject: c++/10832: spurious compiler errors for definition of explicit specialisation of template member function of explicitly specialised class
Date: Sat, 17 May 2003 07:36:00 -0000	[thread overview]
Message-ID: <20030517073055.8641.qmail@sources.redhat.com> (raw)


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


                 reply	other threads:[~2003-05-17  7:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030517073055.8641.qmail@sources.redhat.com \
    --to=gprentice@paradise.net.nz \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).