This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
19980824 member template specialization bugs?
- To: egcs-bugs at cygnus dot com
- Subject: 19980824 member template specialization bugs?
- From: "Reid M. Pinchback" <reidmp at MIT dot EDU>
- Date: Mon, 31 Aug 1998 12:12:49 -0400
- Cc: reidmp at MIT dot EDU
Using the 19980824 snapshot on an alpha-dec-osf4.0d I ran
into some things that I think may be template specialization
bugs. The specialization syntax can get a bit non-intuitive so
I've tried verifying this against the CD2 docs, but I'll admit
to going a bit cross-eyed in the process of attempting that. :-)
Have I missed something syntactically obvious?
=========================== 8< cut here 8< ===========================
/*
** member template specialization bugs
**
** to build:
** define 1 of the 3 cases and then "gcc -c bug.cpp -o bug"
**
** case 1 compiles without error
**
** This looks like correct behaviour to me.
**
** case 2 gives the error:
** bug.cpp:47: template parameters not used in partial specialization:
** bug.cpp:47: `X'
** bug.cpp: In function `int main(int, char **)':
** bug.cpp:63: confused by earlier errors, bailing out
** make: *** [bug.o] Error 1
**
** I may be missing something, but I can't find anything in CD2 that
** requires that the template parameter for the enclosing class be used
** in a complete specialization of a member template class contained
** in the body of that enclosing class. If that were the case, I'd
** expect CASE1 not to compile.
**
** case 3 gives the error:
** bug.cpp: In function `int main(int, char **)':
** bug.cpp:63: `t' is not a member of type `super<int>::super<int>::a<char>'
** bug.cpp:63: parse error before `='
** make: *** [bug.o] Error 1
**
** I believe this is a different problem. Specializations can contain
** new members (CD2 shows an example of that in 14.5.4.3), so this
** looks like a bug to me.
*/
#define CASE3
#if defined(CASE1)
template <class X> class bug {
template <class Y> class a { typedef Y t; };
};
#elif defined(CASE2)
template <class X> class bug {
template <class Y> class a {};
template<> class a<char> { typedef X t; };
};
#else
template <class X> class super {
template <class Y> class a {};
};
template <class X> class bug : public super<X> {
template<> class a<char> { typedef char t; };
};
#endif
main(int argc, char * argv[]) {
bug<int>::a<char>::t mychar='c';
}
=========================== 8< cut here 8< ===========================
====================================================
= Reid M. Pinchback =
= I/T Delivery, MIT =
= =
= Email: reidmp@mit.edu =
= URL: http://web.mit.edu/reidmp/www/home.html =
====================================================