This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Mangling of namespace-scoped templates
- To: egcs-patches at cygnus dot com
- Subject: Mangling of namespace-scoped templates
- From: Martin von Loewis <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Fri, 3 Jul 1998 20:58:49 +0200
Namespace qualifications are ignored for template instantiations at
the moment, here's a fix.
Martin
1998-07-03 Martin von Löwis <loewis@informatik.hu-berlin.de>
* method.c (mangling_context): New function.
(build_overload_nested_name): Call it.
(build_qualified_name): Likewise.
--- /dev/null Mon Jul 18 01:46:18 1994
+++ g++.ns/template5.C Fri Jul 3 20:55:51 1998
@@ -0,0 +1,33 @@
+//Check whether namespace-scoped template instantiations
+//are mangled differently.
+
+namespace X{
+ template<class T>
+ struct Y{
+ int f(T){
+ return 1;
+ }
+ template<class X>void g(){}
+ };
+}
+
+template<class T>
+struct Y{
+ int f(T){
+ return 2;
+ }
+};
+
+int main()
+{
+ X::Y<int> z;
+ if (z.f(4) != 1)
+ return 1;
+ z.template g<long>();
+
+ Y<int> z1;
+ if (z1.f(5) != 2)
+ return 1;
+ return 0;
+}
+
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/03 18:49:21
*************** issue_ktype (decl)
*** 411,416 ****
--- 411,438 ----
return FALSE;
}
+ /* Return the context of a decl to be used in mangling.
+ This is usually DECL_CONTEXT, except for template instantiations,
+ where it is the context of the template declaration. */
+
+ static tree
+ mangling_context (decl)
+ tree decl;
+ {
+ tree ctx;
+ if (TREE_CODE (decl) == TYPE_DECL
+ && TYPE_LANG_SPECIFIC(TREE_TYPE (decl))
+ && CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)))
+ {
+ ctx = CP_DECL_CONTEXT (CLASSTYPE_TI_TEMPLATE (TREE_TYPE (decl)));
+ /* For nested templates, return the instantiated container,
+ not the container of the declaration. */
+ if (TREE_CODE (ctx) == NAMESPACE_DECL)
+ return ctx;
+ }
+ return CP_DECL_CONTEXT (decl);
+ }
+
static void
build_overload_nested_name (decl)
tree decl;
*************** build_overload_nested_name (decl)
*** 424,430 ****
if (decl == global_namespace)
return;
! context = CP_DECL_CONTEXT (decl);
/* try to issue a K type, and if we can't continue the normal path */
if (!(ktypelist && issue_ktype (context)))
--- 446,452 ----
if (decl == global_namespace)
return;
! context = mangling_context (decl);
/* try to issue a K type, and if we can't continue the normal path */
if (!(ktypelist && issue_ktype (context)))
*************** build_qualified_name (decl)
*** 949,958 ****
if (check_ktype (context, FALSE) == -1)
{
/* count type and namespace scopes */
! while (DECL_CONTEXT (context) && DECL_CONTEXT (context) != global_namespace)
{
i += 1;
! context = DECL_CONTEXT (context);
if (check_ktype (context, FALSE) != -1) /* found it! */
break;
if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')
--- 971,980 ----
if (check_ktype (context, FALSE) == -1)
{
/* count type and namespace scopes */
! while (mangling_context (context) != global_namespace)
{
i += 1;
! context = mangling_context (context);
if (check_ktype (context, FALSE) != -1) /* found it! */
break;
if (TREE_CODE_CLASS (TREE_CODE (context)) == 't')