specialization bug

Martin Sebor sebor@roguewave.com
Mon Oct 16 09:45:00 GMT 2000


Neil Radisch wrote:
> 
> gcc version - 2.95.2 19991024
> system type - sparc-sun-solaris2.6
> comand line - gcc ttest2.cpp -lstdc++
> compiler output:
> --------
> ttest2.cpp:8: explicit specialization in non-namespace scope `narf<C>'

As the compiler says (in a not very helpful way), you can't declare an
explicit specialization in class scope. From 14.7.3, p2:

-2- An explicit specialization shall be declared in the namespace of
which the template is a member, or, for member templates, in the
namespace of which the enclosing class or enclosing class template is a
member.

There is no way to explicitly specialize a member template or a class
template without also explicitly specializing the enclosing template
(14.7.3, p18).

Regards
Martin

> ttest2.cpp:8: enclosing class templates are not explicitly specialized
> ttest2.cpp:8: syntax error before `{'
> ttest2.cpp:10: warning: all member functions in class `narf<C>' are
> private
> ttest2.cpp:10: semicolon missing after declaration of `narf<C>'
> ttest2.cpp:10: parse error at null character
> ttest2.cpp: In function `bool gorp()':
> ttest2.cpp:13: `mData' undeclared (first use this function)
> ttest2.cpp:13: (Each undeclared identifier is reported only once
> ttest2.cpp:13: for each function it appears in.)
> ttest2.cpp:13: implicit declaration of function `int foo(...)'
> ttest2.cpp: At top level:
> ttest2.cpp:14: parse error before `}'
> --------------------------------------------------
> preprocessed file:
> ------------------------------------------------
> # 1 "ttest2.cpp"
> template <class C> class narf
> {
> private:
> 
>  C mData;
> 
>  template <class T> bool foo(T &v) { return true; }
>  template <> bool foo(bool &v) { v = true; return false; }
> 
> public:
> 
>  narf() {}
>  bool gorp() { return foo(mData); }
> };
> 
> int main(int argc,char *argv[])
> {
>  narf<int> i;
>  narf<bool> b;
> 
>  return 0;
> }
> ---------------------------------------------------------------
> 
>   ------------------------------------------------------------------------
>                  Name: ttest2.cpp
>    ttest2.cpp    Type: unspecified type (application/octet-stream)
>              Encoding: quoted-printable


More information about the Gcc-bugs mailing list