]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: [PR123025] Catch Old-style character declarations.
authorHarald Anlauf <anlauf@gmx.de>
Mon, 8 Dec 2025 19:48:29 +0000 (11:48 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Mon, 8 Dec 2025 20:48:06 +0000 (12:48 -0800)
Before this patch we missed the two cases here:

character*5 string5         ! Gives obsolescent message
character*(5) string5const  ! Silent with constant
character*(2+3) string5expr ! Silent with expression

PR fortran/123025

gcc/fortran/ChangeLog:

* decl.cc (match_char_length): Add a check for the
obsolete '*' style of character declarations in the
alternate branch of checking so we dont miss two
use cases:

gcc/testsuite/ChangeLog:

* gfortran.dg/assumed_charlen_dummy.f90: These tests failed
with the change because of the default -pedantic option
used by the dg.exp mechanisms. Overide this default.
* gfortran.dg/automatic_char_len_1.f90: Ditto.
* gfortran.dg/entry_23.f: Ditto.
* gfortran.dg/finalize_59.f90: Dito.
* gfortran.dg/g77/f90-intrinsic-bit.f: Ditto.
* gfortran.dg/g77/f90-intrinsic-mathematical.f: Ditto.
* gfortran.dg/g77/f90-intrinsic-numeric.f: Ditto.
* gfortran.dg/g77/intrinsic-unix-bessel.f: Ditto.
* gfortran.dg/g77/intrinsic-unix-erf.f: Ditto.
* gfortran.dg/initialization_9.f90: Ditto.
* gfortran.dg/intrinsic_actual_4.f90: Ditto.
* gfortran.dg/namelist_assumed_char.f90: Ditto.
* gfortran.dg/pr15140.f90: Ditto.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
14 files changed:
gcc/fortran/decl.cc
gcc/testsuite/gfortran.dg/assumed_charlen_dummy.f90
gcc/testsuite/gfortran.dg/automatic_char_len_1.f90
gcc/testsuite/gfortran.dg/entry_23.f
gcc/testsuite/gfortran.dg/finalize_59.f90
gcc/testsuite/gfortran.dg/g77/f90-intrinsic-bit.f
gcc/testsuite/gfortran.dg/g77/f90-intrinsic-mathematical.f
gcc/testsuite/gfortran.dg/g77/f90-intrinsic-numeric.f
gcc/testsuite/gfortran.dg/g77/intrinsic-unix-bessel.f
gcc/testsuite/gfortran.dg/g77/intrinsic-unix-erf.f
gcc/testsuite/gfortran.dg/initialization_9.f90
gcc/testsuite/gfortran.dg/intrinsic_actual_4.f90
gcc/testsuite/gfortran.dg/namelist_assumed_char.f90
gcc/testsuite/gfortran.dg/pr15140.f90

index dfedb962bad60d08236669075fec88ca05c5b675..0e55171068b9082c3b5a2fdec651caab997b27df 100644 (file)
@@ -1217,6 +1217,10 @@ match_char_length (gfc_expr **expr, bool *deferred, bool obsolescent_check)
       goto syntax;
     }
 
+  if (obsolescent_check
+      && !gfc_notify_std (GFC_STD_F95_OBS, "Old-style character length at %C"))
+    return MATCH_ERROR;
+
   return MATCH_YES;
 
 syntax:
index 04f0b9faaded773405f1f5ec4a322e1673193dbd..2e0e77cf512d3cfd8909150a90a939a411228ea1 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-options " " }
 ! Test the fix for PR fortran/39893.
 ! Original testcase provided by Deji Akingunola.
 ! Reduced testcase provided by Dominique d'Humieres.
index 3ccfcb70de8053d5d791c37b461fd6d93d26b876..7f102b78dc5384c2872f5c3061fcd475dc591679 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-options " " }
 ! PR18082 - Compiler would get stuck in loop, whilst treating
 ! the assignments.
 ! Test is one of PR cases.
index ebc5f6681aa279a5032bacd7d900dc928e132c7e..d10ea92acf9179b0664dba46ce99cf746d85b036 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-options " " }
 ! PR 97799 - this used to segfault intermittently.
 ! Test case by George Hockney.
       PROGRAM MAIN
index 8be5f7123a1ac727004a0be8e9255d5f36a65ecd..e9e68d429eaf7dbfed18b94f9cb4d5281f81206b 100644 (file)
@@ -187,7 +187,7 @@ Program Cds_Principal
    Type(Uef_Vector)                                    :: Cds_Mod_Les_materiaux
    Type (Cds_Materiau_Acier_EC)                        :: acier_ec
    Class (Cds_Materiau), pointer                       :: pt_materiau
-   Character *(8)                                      :: nom_materiau
+   Character(len=8)                                    :: nom_materiau
 !-------------------------------------------------------------------------------------------------
       CaLL  Cds_Mod_Les_materiaux%Add (acier_ec)
       nom_materiau = "12345678"
@@ -199,7 +199,7 @@ Function Get_Pt_Materiau_nom (vecteur, nom_materiau)
     !   Fonction :
     !--------------------
      ! Parametres en entree
-    Character *(8), Intent (in)        :: nom_materiau
+    Character(len=8), Intent (in)        :: nom_materiau
     Type (Uef_Vector)          , Intent (inout)     :: vecteur
 
     ! Parametres en sortie
index 0ce45decfb9ca592b4193bf40a62f108818dea62..2f03db18b550e80cdbd0a92b61d6b788effc4a18 100644 (file)
@@ -1,4 +1,5 @@
 c { dg-do run }
+c { dg-options " " }
 c  f90-intrinsic-bit.f
 c
 c Test Fortran 90 
index d151fd0a38d8f47cbda6a691cf250289069ec43b..f07336e939efc5b897b4836019a7d9518e90e037 100644 (file)
@@ -1,4 +1,5 @@
 c { dg-do run }
+c { dg-options " " }
 c  f90-intrinsic-mathematical.f
 c
 c Test Fortran 90 intrinsic mathematical functions - Section 13.10.3 and
index c8d7c5695240c77eaeda55ecffc32304300a9c58..c01efe6d437fdac19b5e41ba9eae39f6dad4f2a4 100644 (file)
@@ -1,4 +1,5 @@
 c { dg-do run }
+c { dg-options " " }
 c  f90-intrinsic-numeric.f
 c
 c Test Fortran 90 intrinsic numeric functions - Section 13.10.2 and 13.13 
index b388806399b5db0c9afeafa707b34473016c056d..406a8e421659ee1b1299ad256affdfcf55087c37 100644 (file)
@@ -1,4 +1,5 @@
 c { dg-do run }
+c { dg-options " " }
 c  intrinsic-unix-bessel.f
 c
 c Test Bessel function intrinsics.  
index 250519af7b7a7470621467b1a06c0e8413a22c84..6ed9590b703cb67ec1865fc005dc260672ffbbd2 100644 (file)
@@ -1,4 +1,5 @@
 c { dg-do run }
+c { dg-options " " }
 c  intrinsic-unix-erf.f
 c
 c Test Bessel function intrinsics.  
index d90404748803b2defed8b2e00c878a36cad86fd0..fe7ca634a59400e0e77d092123a2045d0408dbef 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-options " " }
 !
 ! PR fortran/31639
 ! Contributed by Martin Michlmayr <tbm AT cyrius DOT com>
index 4521c968af73a7a2432ed17aadab6dbebd5fa5c8..3358b4aeef0ac668c6733c6fb231d0bbc9df9bff 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-options " " }
 ! Tests the fix for PR27900, in which an ICE would be caused because
 ! the actual argument LEN had no type.
 !
index b7d063c78b06bccd9f912faf35d53b85372240b4..25edf648c0ae45d361245bf81fd8774b9ec13a9b 100644 (file)
@@ -8,7 +8,7 @@
 ! Add -std=f95, add bar()
 !
 subroutine foo(c)
-  character*(*) c
+  character*(*) c   ! { dg-warning "Old-style character length" }
   namelist /abc/ c  ! { dg-error "nonconstant character length in namelist" }
 end subroutine
 
index 80c08dda95414fed756c592327331ecc4a7f4ffd..7f9af4fbd76bc608e6b2593d700d04aae2dd4674 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-options "-std=legacy" }
 ! PR 15140: we used to fail an assertion, because we don't use the
 ! argument of the subroutine directly, but instead use a copy of it.
 function M(NAMES)