Patchwork [Fortran,OOP] PR 46313: class container naming collisions (once again)

login
register
mail settings
Submitter Janus Weil
Date Jan. 8, 2011, 6:28 p.m.
Message ID <AANLkTinJrmH5E2nfeeyTR3XJ7HLwbNtYVpLDFEgyT4_k@mail.gmail.com>
Download mbox | patch
Permalink /patch/77972/
State New
Headers show

Comments

Janus Weil - Jan. 8, 2011, 6:28 p.m.
Hi all,

I plan to commit the attached patch as obvious, unless anyone objects.
It fixes another case of class container naming collisions (comment
#12/#19 in the PR). We had fixed a few such cases before, and I hope
there are not much more left ...

I am in the process of regtesting and will commit tomorrow if no one
objects until then.

Cheers,
Janus



2011-01-08  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/46313
	* class.c (get_unique_type_string): Make type name start with upper
	case letter.


2011-01-08  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/46313
	* gfortran.dg/class_35.f90: New.
Janus Weil - Jan. 9, 2011, 10:37 a.m.
> I plan to commit the attached patch as obvious, unless anyone objects.
> It fixes another case of class container naming collisions (comment
> #12/#19 in the PR). We had fixed a few such cases before, and I hope
> there are not much more left ...

Committed as r168610 after successful regstrap.

Cheers,
Janus



> 2011-01-08  Janus Weil  <janus@gcc.gnu.org>
>
>        PR fortran/46313
>        * class.c (get_unique_type_string): Make type name start with upper
>        case letter.
>
>
> 2011-01-08  Janus Weil  <janus@gcc.gnu.org>
>
>        PR fortran/46313
>        * gfortran.dg/class_35.f90: New.
>

Patch

Index: gcc/testsuite/gfortran.dg/class_35.f90
===================================================================
--- gcc/testsuite/gfortran.dg/class_35.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/class_35.f90	(revision 0)
@@ -0,0 +1,26 @@ 
+! { dg-do run }
+!
+! PR 46313: [OOP] class container naming collisions
+!
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+
+module one
+  type two_three
+  end type
+end module
+
+module one_two
+  type three
+  end type
+end module
+
+use one
+use one_two
+class(two_three), allocatable :: a1
+class(three), allocatable :: a2
+
+if (same_type_as(a1,a2)) call abort()
+
+end 
+
+! { dg-final { cleanup-modules "one one_two" } }
Index: gcc/fortran/class.c
===================================================================
--- gcc/fortran/class.c	(revision 168586)
+++ gcc/fortran/class.c	(working copy)
@@ -116,13 +116,16 @@  gfc_class_null_initializer (gfc_typespec *ts)
 
 static void
 get_unique_type_string (char *string, gfc_symbol *derived)
-{  
+{
+  char dt_name[GFC_MAX_SYMBOL_LEN+1];
+  sprintf (dt_name, "%s", derived->name);
+  dt_name[0] = TOUPPER (dt_name[0]);
   if (derived->module)
-    sprintf (string, "%s_%s", derived->module, derived->name);
+    sprintf (string, "%s_%s", derived->module, dt_name);
   else if (derived->ns->proc_name)
-    sprintf (string, "%s_%s", derived->ns->proc_name->name, derived->name);
+    sprintf (string, "%s_%s", derived->ns->proc_name->name, dt_name);
   else
-    sprintf (string, "_%s", derived->name);
+    sprintf (string, "_%s", dt_name);
 }