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]

Explicit specialization of member template function





Dear sir,

When I wrote a class which has a member template function,
G++ reported an error when I defined an explicit specialization of the template
function.

I am wondering whether this is a compiler bug, I made a mistake,
or ANSI C++ does not allow the explicit specialization of member template
functions.

(By the way, I was able to define an explicit specialization
of a global template function.)

Attached is a simplified code, which was failed to be compiled.
When the following line is removed from the code:

   template <>      static int baz <0> (void) { return -1; }

the code was compiled successfully and ran as I expected.

Thank you very much.

Kiyoshi Ono  E-mail: ono@jp.ibm.com
Telephone: +81-46-215-4916  FAX: +81-46-273-7425
IBM Japan, Ltd.

-----------------------------------------------------------------------------------------


   GCC Version:  2.95.2
   System Type:  Red Had Linux Release 6.2 (Zoot)
   Kernel:       Linux version 2.2.14-5.0 (root@porky.devel.redhat.com)
                    (gcc version egcs-2.91.66 19990314/Linux
                    (egcs-1.1.2 release)) #1 Tue Mar 7 21:07:39 EST 2000
   g++ Options:  None

--------------------------------------------------------------------

g++ -v --save-temps template-Q2.C

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp -lang-c++ -v -D__GNUC__=2
-D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__
-Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux
-Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386
-D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro
-D__pentiumpro__ template-Q2.C template-Q2.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3
 /usr/local/include

/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../i686-pc-linux-gnu/include

 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cc1plus template-Q2.ii -quiet
-dumpbase template-Q2.cc -version -o template-Q2.s
GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled by GNU C
version 2.95.2 19991024 (release).

template-Q2.C:12: explicit specialization in non-namespace scope `C'
template-Q2.C:12: invalid use of undefined type `struct C'
template-Q2.C:10: forward declaration of `struct C'
template-Q2.C:12: confused by earlier errors, bailing out

--------- template-Q2.ii file ---------------------------------------
# 1 "template-Q2.C"

template <int N> int foo (void) { return N; }
template <>      int foo <0> (void) { return -1; }

struct C
{
  template <int N> static int baz (void) { return N; }
  template <>      static int baz <0> (void) { return -1; }
};

int main (int, char **)
{
     foo <10> ()  ;
     foo <0> ()  ;

     C::baz <10> ()  ;
     C::baz <0> ()  ;

  return 0;
}

--------- end of template-Q2.ii file ---------------------------------



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