This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Patch for explicit instantiation of member templates
- To: Brendt Wohlberg <brendt at dip dot ee dot uct dot ac dot za>, egcs at cygnus dot com
- Subject: Patch for explicit instantiation of member templates
- From: Mark Mitchell <mmitchell at usa dot net>
- Date: Wed, 17 Dec 1997 11:23:55 -0800
- Cc: Jason Merrill <jason at cygnus dot com>
- Reply-To: egcs at cygnus dot com
Brendt --
You reported two problems today. The first results from your use of
-f-name-mangling-version-0 rather than -fguiding-decls.
I have attached a fix for the second, regarding code like this:
template <class T>
struct A
{
template <class U>
void f(U u) {}
};
template void A<int>::f<char>(char);
template void A<double>::f(long);
The member templates are now instantiated as expected.
supernova% test-g++ -c test2.cc
supernova% nm test2.o | test-c++filt
00000000 ? __FRAME_BEGIN__
00000000 T void A<int>::f<char>(char)
00000018 T void A<double>::f<long>(long)
00000000 t gcc2_compiled.
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
Wed Dec 17 11:16:52 1997 Mark Mitchell <mmitchell@usa.net>
* pt.c (is_member_template): Remove bogus code for
specializations.
(check_explicit_specialization): Correctly recognize
instantiations of member templates.
Index: pt.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/pt.c,v
retrieving revision 1.1.1.6
diff -c -p -r1.1.1.6 pt.c
*** pt.c 1997/12/17 06:31:08 1.1.1.6
--- pt.c 1997/12/17 19:00:00
*************** is_member_template (t)
*** 150,156 ****
if (TREE_CODE (t) != FUNCTION_DECL
&& !DECL_FUNCTION_TEMPLATE_P (t))
! /* Anything that isn't a template or a template function is
certainly not a member template. */
return 0;
--- 162,168 ----
if (TREE_CODE (t) != FUNCTION_DECL
&& !DECL_FUNCTION_TEMPLATE_P (t))
! /* Anything that isn't a function or a template function is
certainly not a member template. */
return 0;
*************** is_member_template (t)
*** 174,206 ****
int template_class_levels = 0;
tree ctx = DECL_CLASS_CONTEXT (t);
! if (CLASSTYPE_TEMPLATE_INFO (ctx))
! {
! tree args;
! /* Here, we should really count the number of levels
! deep ctx is, making sure not to count any levels that
! are just specializations. Since there are no member
! template classes yet, we don't have to do all that. */
! if (!CLASSTYPE_TEMPLATE_SPECIALIZATION (ctx))
template_class_levels = 1;
! else
! {
! int i;
!
! args = CLASSTYPE_TI_ARGS (ctx);
!
! if (args == NULL_TREE)
! template_class_levels = 1;
! else
! for (i = 0; i < TREE_VEC_LENGTH (args); ++i)
! if (uses_template_parms (TREE_VEC_ELT (args, i)))
! {
! template_class_levels++;
! break;
! }
! }
}
if (parm_levels > template_class_levels)
--- 186,212 ----
int template_class_levels = 0;
tree ctx = DECL_CLASS_CONTEXT (t);
! /* NB - The code below does not yet handle template class
! members, e.g.
!
! template <class T> class C { template <class U> class D; }}
! correctly. In that case, the D should have level 2. */
! if (CLASSTYPE_TEMPLATE_INFO (ctx))
! {
! tree args = CLASSTYPE_TI_ARGS (ctx);
! int i;
!
! if (args == NULL_TREE)
template_class_levels = 1;
! else
! for (i = 0; i < TREE_VEC_LENGTH (args); ++i)
! if (uses_template_parms (TREE_VEC_ELT (args, i)))
! {
! template_class_levels++;
! break;
! }
}
if (parm_levels > template_class_levels)
*************** check_explicit_specialization (declarato
*** 497,503 ****
&& !processing_explicit_specialization (template_count)
&& !is_friend)
{
! if (! have_def && ! template_header_count && ! ctype)
/* This is not an explict specialization. It must be
an explicit instantiation. */
return 2;
--- 503,509 ----
&& !processing_explicit_specialization (template_count)
&& !is_friend)
{
! if (! have_def && ! template_header_count)
/* This is not an explict specialization. It must be
an explicit instantiation. */
return 2;