aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2016-02-14 12:23:59 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2016-02-14 12:23:59 +0000
commit60cb4ef5550eac9581ef1b36607b5fb297eddce2 (patch)
treec03f8e2995de5d99633664ea80baa6f1fa4665c4 /gcc
parentcdc647c36f1a5878f8ea518c6865010abd9d7e69 (diff)
downloadgcc-60cb4ef5550eac9581ef1b36607b5fb297eddce2.zip
gcc-60cb4ef5550eac9581ef1b36607b5fb297eddce2.tar.gz
gcc-60cb4ef5550eac9581ef1b36607b5fb297eddce2.tar.bz2
re PR fortran/60526 (Accepts-invalid: Variable name same as type name)
2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/60526 * decl.c (build_sym): If the name has already been defined as a type, issue error and return false. 2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/60526 * gfortran.dg/type_decl_4.f90: New test. From-SVN: r233410
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/decl.c20
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/type_decl_4.f907
4 files changed, 38 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index de669e0..5ef62ae 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/60526
+ * decl.c (build_sym): If the name has already been defined as a
+ type, issue error and return false.
+
2016-02-12 David Malcolm <dmalcolm@redhat.com>
PR other/69554
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index df81369..a31ea49 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1215,10 +1215,30 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
{
symbol_attribute attr;
gfc_symbol *sym;
+ int nlen;
+ char u_name[GFC_MAX_SYMBOL_LEN + 1];
+ gfc_symtree *st;
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. */
+
+ nlen = strlen(name);
+ gcc_assert (nlen <= GFC_MAX_SYMBOL_LEN);
+ strncpy (u_name, name, nlen + 1);
+ u_name[0] = TOUPPER(u_name[0]);
+
+ st = gfc_find_symtree (gfc_current_ns->sym_root, u_name);
+
+ if (st != 0)
+ {
+ gfc_error ("Symbol %qs at %C also declared as a type at %L", name,
+ &st->n.sym->declared_at);
+ return false;
+ }
+
/* Start updating the symbol table. Add basic type attribute if present. */
if (current_ts.type != BT_UNKNOWN
&& (sym->attr.implicit_type == 0
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5e5dff7..4b494b1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-14 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ PR fortran/60526
+ * gfortran.dg/type_decl_4.f90: New test.
+
2016-02-14 Alan Modra <amodra@gmail.com>
PR testsuite/68886
diff --git a/gcc/testsuite/gfortran.dg/type_decl_4.f90 b/gcc/testsuite/gfortran.dg/type_decl_4.f90
new file mode 100644
index 0000000..5c3ddb8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/type_decl_4.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program main
+ type Xx ! { dg-error "Symbol 'xx' at .1. also declared as a type at .2." }
+ end type Xx
+ real :: Xx ! { dg-error "Symbol 'xx' at .1. also declared as a type at .2." }
+
+end program main