]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/30239 (duplicate data type assignment not detected)
authorDaniel Kraft <d@domob.eu>
Fri, 22 Aug 2008 20:36:12 +0000 (22:36 +0200)
committerDaniel Kraft <domob@gcc.gnu.org>
Fri, 22 Aug 2008 20:36:12 +0000 (22:36 +0200)
2008-08-22  Daniel Kraft  <d@domob.eu>

PR fortran/30239
* symbol.c (gfc_add_type): Warn on -Wsurprising if a function-result
type is re-declared but neither -pedantic nor -std=f* is given and so
this is no error.
* invoke.texi (-Wsurprising): Document this new behaviour.

From-SVN: r139499

gcc/fortran/ChangeLog
gcc/fortran/invoke.texi
gcc/fortran/symbol.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/duplicate_type_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/duplicate_type_2.f90 [new file with mode: 0644]

index 1b588cd9d9ca9549a2bb99cfcc5aa552b5ec0570..67c1facb17af92b0c38c14d36e1bee32def82472 100644 (file)
@@ -1,3 +1,11 @@
+2008-08-22  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/30239
+       * symbol.c (gfc_add_type): Warn on -Wsurprising if a function-result
+       type is re-declared but neither -pedantic nor -std=f* is given and so
+       this is no error.
+       * invoke.texi (-Wsurprising): Document this new behaviour.
+
 2008-08-22  Daniel Kraft  <d@domob.eu>
 
        * gfortran.h (in_prefix): Removed from this header.
index b2370d4de0ef41d58826e6db2954f85add49915e..b854ce4b3b88e749c238d99e2a949a92762a8478 100644 (file)
@@ -757,6 +757,10 @@ A LOGICAL SELECT construct has three CASE statements.
 
 @item
 A TRANSFER specifies a source that is shorter than the destination.
+
+@item
+The type of a function result is declared more than once with the same type.  If
+@option{-pedantic} or standard-conforming mode is enabled, this is an error.
 @end itemize
 
 @item -Wtabs
index f49f773d20e6b1a81bfff0232c406747f6d214a9..e16406d471694b2968c5a796f13b6c8b7c53eedc 100644 (file)
@@ -1540,9 +1540,11 @@ gfc_add_type (gfc_symbol *sym, gfc_typespec *ts, locus *where)
          gfc_error (msg, sym->name, where, gfc_basic_typename (sym->ts.type));
          return FAILURE;
        }
-      else if (gfc_notify_std (GFC_STD_GNU, msg, sym->name, where,
-                              gfc_basic_typename (sym->ts.type)) == FAILURE)
+      if (gfc_notify_std (GFC_STD_GNU, msg, sym->name, where,
+                         gfc_basic_typename (sym->ts.type)) == FAILURE)
        return FAILURE;
+      if (gfc_option.warn_surprising)
+       gfc_warning (msg, sym->name, where, gfc_basic_typename (sym->ts.type));
     }
 
   flavor = sym->attr.flavor;
index bf4d14e07077c3ac3b163903a82a68eecf1b6c0d..4ee805b5b4eeb5d1b8f2102076ee87913ed6ddb4 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-22  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/30239
+       * gfortran.dg/duplicate_type_1.f90: New test.
+       * gfortran.dg/duplicate_type_2.f90: New test.
+
 2008-08-22  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.dg/tree-ssa/pr21658.c (dg-options): Use -fdump-tree-ccp1-details.
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_1.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_1.f90
new file mode 100644 (file)
index 0000000..c76c45d
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+
+! PR fortran/30239
+! Check for errors when a symbol gets declared a type twice, even if it
+! is the same.
+
+INTEGER FUNCTION foo ()
+  IMPLICIT NONE
+  INTEGER :: foo ! { dg-error "basic type of" }
+  INTEGER :: foo ! { dg-error "basic type of" }
+  foo = 42
+END FUNCTION foo
+
+INTEGER FUNCTION bar () RESULT (x)
+  IMPLICIT NONE
+  INTEGER :: x ! { dg-error "basic type of" }
+
+  INTEGER :: y
+  INTEGER :: y ! { dg-error "basic type of" }
+
+  x = 42
+END FUNCTION bar
diff --git a/gcc/testsuite/gfortran.dg/duplicate_type_2.f90 b/gcc/testsuite/gfortran.dg/duplicate_type_2.f90
new file mode 100644 (file)
index 0000000..5b86dc6
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-std=gnu -Wsurprising" }
+
+! PR fortran/30239
+! Check for errors when a symbol gets declared a type twice, even if it
+! is the same.
+
+INTEGER FUNCTION foo ()
+  IMPLICIT NONE
+  INTEGER :: foo ! { dg-warning "basic type of" }
+  INTEGER :: foo ! { dg-warning "basic type of" }
+  foo = 42
+END FUNCTION foo
+
+INTEGER FUNCTION bar () RESULT (x)
+  IMPLICIT NONE
+  INTEGER :: x ! { dg-warning "basic type of" }
+
+  INTEGER :: y
+  INTEGER :: y ! { dg-error "basic type of" }
+
+  x = 42
+END FUNCTION bar