specialization bug
Neil Radisch
nradisch@panix.com
Mon Oct 16 12:21:00 GMT 2000
I get it now.. thanks.
Too bad though, the "incorrect" syntax was alot
more elegant.
Neil
----- 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 2:51 PM
Subject: Re: specialization bug
> Neil Radisch wrote:
> >
> > 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.
>
> No, that wasn't a quote, just a gist of the paragraph. It amounts to the
> same thing (the "or" should have been "of").
>
> > 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.
>
> Perhaps, but it's not allowed (if 2.91 accepts it then it's a bug).
>
> >
> > 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); }
>
> This is not going to work either because of 14.7.3, p6:
>
> -6- If a template, a member template or the member of a class template
> is explicitly specialized then that specialization shall be declared
> before the first use of that specialization that would cause an implicit
> instantiation to take place, in every translation unit in which such a
> use occurs; no diagnostic is required...
>
> You'll have to define the member functions outside of the template and
> after the definition of the explicit specialization.
>
> Martin.
>
> > };
> >
> > #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
> > >
>
> --
> ==============================================
> Martin Sebor, Lead Software Engineer
> C++ Standards Group, Rogue Wave Software, Inc.
> sebor@roguewave.com (303) 545-3287
More information about the Gcc-bugs
mailing list