re PR fortran/86935 (Bad locus in ASSOCIATE statement)
authorJanus Weil <janus@gcc.gnu.org>
Wed, 22 Aug 2018 19:31:40 +0000 (21:31 +0200)
committerJanus Weil <janus@gcc.gnu.org>
Wed, 22 Aug 2018 19:31:40 +0000 (21:31 +0200)
fix PR 86935

2018-08-22  Janus Weil  <janus@gcc.gnu.org>

PR fortran/86935
* match.c (gfc_match_associate): Improve diagnostics for the ASSOCIATE
statement.

2018-08-22  Janus Weil  <janus@gcc.gnu.org>

PR fortran/86935
* gfortran.dg/associate_3.f90: Update error message.
* gfortran.dg/associate_39.f90: New test case.

From-SVN: r263787

gcc/fortran/ChangeLog
gcc/fortran/match.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/associate_3.f03
gcc/testsuite/gfortran.dg/associate_39.f90 [new file with mode: 0644]

index 88edff3..6bbf99c 100644 (file)
@@ -1,3 +1,9 @@
+2018-08-22  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/86935
+       * match.c (gfc_match_associate): Improve diagnostics for the ASSOCIATE
+       statement.
+
 2018-08-22  Andrew Benson  <abensonca@gmail.com>
 
        * module.c (load_generic_interfaces): Move call to find_symbol()
index 1ab0e0f..85247dd 100644 (file)
@@ -1889,17 +1889,21 @@ gfc_match_associate (void)
       gfc_association_list* a;
 
       /* Match the next association.  */
-      if (gfc_match (" %n => %e", newAssoc->name, &newAssoc->target)
-           != MATCH_YES)
+      if (gfc_match (" %n =>", newAssoc->name) != MATCH_YES)
+       {
+         gfc_error ("Expected association at %C");
+         goto assocListError;
+       }
+
+      if (gfc_match (" %e", &newAssoc->target) != MATCH_YES)
        {
          /* Have another go, allowing for procedure pointer selectors.  */
          gfc_matching_procptr_assignment = 1;
-         if (gfc_match (" %n => %e", newAssoc->name, &newAssoc->target)
-             != MATCH_YES)
-           {
-             gfc_error ("Expected association at %C");
-             goto assocListError;
-           }
+         if (gfc_match (" %e", &newAssoc->target) != MATCH_YES)
+           {
+             gfc_error ("Invalid association target at %C");
+             goto assocListError;
+           }
          gfc_matching_procptr_assignment = 0;
        }
       newAssoc->where = gfc_current_locus;
index 59a9038..8e70d05 100644 (file)
@@ -1,5 +1,11 @@
 2018-08-22  Janus Weil  <janus@gcc.gnu.org>
 
+       PR fortran/86935
+       * gfortran.dg/associate_3.f90: Update error message.
+       * gfortran.dg/associate_39.f90: New test case.
+
+2018-08-22  Janus Weil  <janus@gcc.gnu.org>
+
        PR fortran/86888
        * gfortran.dg/alloc_comp_basics_6.f90: Update an error message and add
        an additional case.
index 20a375d..da7bec9 100644 (file)
@@ -13,7 +13,7 @@ PROGRAM main
 
   ASSOCIATE (a => 1) 5 ! { dg-error "Junk after ASSOCIATE" }
 
-  ASSOCIATE (x =>) ! { dg-error "Expected association" }
+  ASSOCIATE (x =>) ! { dg-error "Invalid association target" }
 
   ASSOCIATE (=> 5) ! { dg-error "Expected association" }
 
diff --git a/gcc/testsuite/gfortran.dg/associate_39.f90 b/gcc/testsuite/gfortran.dg/associate_39.f90
new file mode 100644 (file)
index 0000000..16357c3
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+!
+! PR 86935: Bad locus in ASSOCIATE statement
+!
+! Contributed by Janus Weil <janus@gcc.gnu.org>
+
+implicit none
+
+type :: t
+  real :: r = 0.5
+  integer :: i = 3
+end type
+
+type(t) :: x
+
+associate (r => x%r, &
+           i => x%ii)   ! { dg-error "Invalid association target" }
+
+end