namespaces and explicit instantiation
Martin von Loewis
martin@mira.isdn.cs.tu-berlin.de
Thu Jul 2 17:54:00 GMT 1998
> The result of the above errors is that files using namespaces won't link
> together.
The bug is that it uses the namespace of instantiation for mangling,
instead of the namespace of declaration. Here's a fix.
Martin
1998-07-02 Martin von Löwis <loewis@informatik.hu-berlin.de>
* method.c (build_template_decl_overload): Expect _DECL as first
parameter. Put context temporarily into current_namespace.
* pt.c (check_explicit_specialization): Change caller.
(tsubst): Likewise.
--- /dev/null Mon Jul 18 01:46:18 1994
+++ g++.ns/template4.C Thu Jul 2 21:26:58 1998
@@ -0,0 +1,17 @@
+namespace NS
+{
+template <typename T>
+void solver (){}
+
+}
+
+template<typename T>
+void solver(){}
+
+int main()
+{
+ solver<double>();
+ NS::solver<double>();
+}
+
+
Index: method.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/method.c,v
retrieving revision 1.60
diff -c -p -r1.60 method.c
*** method.c 1998/06/25 03:28:26 1.60
--- method.c 1998/07/02 19:28:40
*************** build_decl_overload (dname, parms, for_m
*** 1630,1646 ****
/* Like build_decl_overload, but for template functions. */
tree
! build_template_decl_overload (dname, parms, ret_type, tparms, targs,
for_method)
! tree dname;
tree parms;
tree ret_type;
tree tparms;
tree targs;
int for_method;
{
! return build_decl_overload_real (dname, parms, ret_type, tparms, targs,
! for_method);
}
--- 1630,1660 ----
/* Like build_decl_overload, but for template functions. */
tree
! build_template_decl_overload (decl, parms, ret_type, tparms, targs,
for_method)
! tree decl;
tree parms;
tree ret_type;
tree tparms;
tree targs;
int for_method;
{
! tree res, saved_ctx;
!
! /* If the template is in a namespace, we need to put that into the
! mangled name. Unfortunately, build_decl_overload_real does not
! get the decl to mangle, so it relies on the current
! namespace. Therefore, we set that here temporarily. */
!
! my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 980702);
! saved_ctx = current_namespace;
! current_namespace = CP_DECL_CONTEXT (decl);
!
! res = build_decl_overload_real (DECL_NAME (decl), parms, ret_type,
! tparms, targs, for_method);
!
! current_namespace = saved_ctx;
! return res;
}
Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.159
diff -c -p -r1.159 pt.c
*** pt.c 1998/06/25 03:28:33 1.159
--- pt.c 1998/07/02 19:28:51
*************** check_explicit_specialization (declarato
*** 1220,1228 ****
DECL_ASSEMBLER_NAME (decl)
= build_template_decl_overload
! (DECL_NAME (decl),
! arg_types,
! TREE_TYPE (TREE_TYPE (tmpl)),
DECL_INNERMOST_TEMPLATE_PARMS (tmpl),
targs, ctype != NULL_TREE);
}
--- 1220,1226 ----
DECL_ASSEMBLER_NAME (decl)
= build_template_decl_overload
! (decl, arg_types, TREE_TYPE (TREE_TYPE (tmpl)),
DECL_INNERMOST_TEMPLATE_PARMS (tmpl),
targs, ctype != NULL_TREE);
}
*************** tsubst (t, args, in_decl)
*** 4712,4719 ****
DECL_ASSEMBLER_NAME (r)
= build_template_decl_overload
! (DECL_NAME (r), arg_types,
! TREE_TYPE (TREE_TYPE (tmpl)),
tparms, targs, member);
}
}
--- 4710,4716 ----
DECL_ASSEMBLER_NAME (r)
= build_template_decl_overload
! (r, arg_types, TREE_TYPE (TREE_TYPE (tmpl)),
tparms, targs, member);
}
}
More information about the Gcc-bugs
mailing list