]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/60526 (Accepts-invalid: Variable name same as type name)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 8 Aug 2016 22:00:37 +0000 (22:00 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 8 Aug 2016 22:00:37 +0000 (22:00 +0000)
2016-08-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/60526
* decl.c (build_sym):  If the name has already been defined as a
type, it has a symtree with an upper case letter at the beginning.
If such a symtree exists, issue an error and exit.  Don't do
this if there is no corresponding upper case letter.

2016-08-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/60526
* gfortran.dg/type_decl_4.f90:  New test.

From-SVN: r239259

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/type_decl_4.f90 [new file with mode: 0644]

index 49cb5fb941c3f125b6110793ae79c8ae0427b268..67ec56c5a0091da2fd9690e5477802ccfb283ee5 100644 (file)
@@ -1,3 +1,12 @@
+2016-08-08  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/60526
+       * decl.c (build_sym):  If the name has already been defined as a
+       type, it has a symtree with an upper case letter at the beginning.
+       If such a symtree exists, issue an error and exit.  Don't do
+       this if there is no corresponding upper case letter.
+
 2016-08-08  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        Backport from trunk:
index adea3f3b1d081e5cec1e8a83a774045905164c78..d4704d32dfdf7fe7e81573293e651fcd89e1f874 100644 (file)
@@ -1194,10 +1194,37 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
 {
   symbol_attribute attr;
   gfc_symbol *sym;
+  int upper;
 
   if (gfc_get_symbol (name, NULL, &sym))
     return false;
 
+  /* Check if the name has already been defined as a type.  The
+     first letter of the symtree will be in upper case then.  Of
+     course, this is only necessary if the upper case letter is
+     actually different.  */
+
+  upper = TOUPPER(name[0]);
+  if (upper != name[0])
+    {
+      char u_name[GFC_MAX_SYMBOL_LEN + 1];
+      gfc_symtree *st;
+      int nlen;
+
+      nlen = strlen(name);
+      gcc_assert (nlen <= GFC_MAX_SYMBOL_LEN);
+      strncpy (u_name, name, nlen + 1);
+      u_name[0] = upper;
+
+      st = gfc_find_symtree (gfc_current_ns->sym_root, u_name);
+
+      if (st)
+       {
+         gfc_error ("Symbol %qs at %C also declared as a type", name);
+         return false;
+       }
+    }
+
   /* Start updating the symbol table.  Add basic type attribute if present.  */
   if (current_ts.type != BT_UNKNOWN
       && (sym->attr.implicit_type == 0
index 27e767f1c994b2a351caadd5f1d8c554853374d2..4765fce5e33996e4b369246c2df5b045fdf9d795 100644 (file)
@@ -1,3 +1,8 @@
+2016-08-08  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/60526
+       * gfortran.dg/type_decl_4.f90:  New test.
+
 2016-08-08  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        Backport from trunk:
diff --git a/gcc/testsuite/gfortran.dg/type_decl_4.f90 b/gcc/testsuite/gfortran.dg/type_decl_4.f90
new file mode 100644 (file)
index 0000000..2aa1d7e
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program main
+  type Xx 
+  end type Xx
+  real :: Xx ! { dg-error "Symbol 'xx' at .* also declared as a type" }
+  
+end program main