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]

Re: specialization bug


I re-read my copy of the spec, and I believe I see what you mean,
though paragraph 18 does not say what you quoted below.
Anyhow, it seems that it becomes impossible to build the
following program given the syntactical restriction
(BTW the OLD_GCC_COMPILER constant refers
  to 2.91 as opposed to the 2.95 I'm using on solaris)
If you as me, the syntax bracketed by OLD_GCC_COMPILER
makes alot more sense in this case. Or maybe there is
something I still don't get.

class narf
{
private:

 template <class T> bool foo(T &v) const { return true; }
#ifdef OLD_GCC_COMPILER
 template <> bool foo(bool &v) { v = true; return false; }
#endif
 template <class T> bool gorp(T data) { return foo(data); }
public:

 narf() {}

 void eat() { int i; gorp(i); }
 void me() { bool b; gorp(b); }
};

#ifndef OLD_GCC_COMPILER
 template <> bool narf::foo<bool>(bool &v) const { v = true; return false; }
#endif

int main(int argc,char *argv[])
{
narf n;
n.eat();
n.me();

 return 0;
}





----- Original Message -----
From: "Martin Sebor" <sebor@roguewave.com>
To: "Neil Radisch" <nradisch@panix.com>
Cc: <gcc-bugs@gcc.gnu.org>
Sent: Monday, October 16, 2000 12:49 PM
Subject: Re: specialization bug


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


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