A function template instantiation fix
Kriang Lerdsuwanakij
lerdsuwa@scf-fs.usc.edu
Mon Oct 27 19:36:00 GMT 1997
Hi,
The patch below fix function template problems when some template
parameters does not appear in either function arguments or return type.
They are not correctly instantiated. Here is a simple test program that
fails during linking - f<long> and f<char> not instantiated and the f()
function calls in main() are not mangled.
#include <iostream.h>
template <class T> int f()
{
return sizeof(T);
}
int main()
{
cout << f<long>() << f<char>() << ' ' << f<long>() << endl;
}
*******************
Sun Oct 26 23:49:55 1997 Kriang Lerdsuwanakij <lerdsuwa@scf.usc.edu>
* pt.c (tsubst): Instantiate template functions properly when
template parameter does not appear in function arguments and
return type.
(comp_template_args): Handle member templates required by
tsubst.
diff -u save/pt.c cp/pt.c
--- save/pt.c Sun Oct 26 00:11:51 1997
+++ cp/pt.c Sun Oct 26 23:49:55 1997
@@ -1157,7 +1157,13 @@
continue;
if (TREE_CODE (nt) != TREE_CODE (ot))
return 0;
- if (TREE_CODE_CLASS (TREE_CODE (ot)) == 't')
+ if (TREE_CODE (nt) == TREE_VEC)
+ {
+ /* For member templates */
+ if (comp_template_args (nt, ot))
+ continue;
+ }
+ else if (TREE_CODE_CLASS (TREE_CODE (ot)) == 't')
{
if (comptypes (ot, nt, 1))
continue;
@@ -2246,14 +2252,6 @@
type = tsubst (type, args, nargs, in_decl);
}
- if (type == TREE_TYPE (t)
- && (! member || ctx == DECL_CLASS_CONTEXT (t)))
- {
- t = copy_node (t);
- copy_lang_decl (t);
- return t;
- }
-
/* Do we already have this instantiation? */
if (DECL_TEMPLATE_INFO (t) != NULL_TREE)
{
@@ -2262,7 +2260,8 @@
for (; decls; decls = TREE_CHAIN (decls))
if (TREE_TYPE (TREE_VALUE (decls)) == type
- && DECL_CLASS_CONTEXT (TREE_VALUE (decls)) == ctx)
+ && DECL_CLASS_CONTEXT (TREE_VALUE (decls)) == ctx
+ && comp_template_args (TREE_PURPOSE (decls), args))
return TREE_VALUE (decls);
}
More information about the Gcc
mailing list