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]

c++/959: Problems with template specialisation and namespaces



>Number:         959
>Category:       c++
>Synopsis:       Problems with template specialisation and namespaces
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 02 06:16:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Kevin Shanahan
>Release:        gcc version 2.95.2 20000220 (Debian GNU/Linux)
>Organization:
>Environment:
Debian Gnu/Linux 2.2 x86

Also tested on http://www.codesourcery.com/gcc-compile.shtml:
gcc version 2.97 20001126 (experimental)
>Description:
When specialising a template function that was declared inside a namespace, the compiler won't always allow the specialisation - see the "how-to-repeat" section for more details.

The error message given is:
template1.cc:10: non-template used as template
template1.cc:10: syntax error before `{'
>How-To-Repeat:
Here is the code that fails to compile:

namespace Foo
{
    template<class T> void bar(const T);
}

template<class T>
void Foo::bar(const T arg) { }

template<>
void Foo::bar(const int arg) { }


I have found a couple of ways to get the code to compile. The first is to put everything inside namespace Foo like this:

namespace Foo
{
    template<class T> void bar(const T);

    template<class T>
    void bar(const T arg) { }

    template<>
    void bar(const int arg) { }
}


The second way, which is less disruptive to the layout of the code is to change the specialisation like this:

template<class T>
void Foo::bar(const int arg) { }

Which seems strange, since T is not used here.
(should the compiler generate a warning in this case?)
>Fix:

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