Hi Harald, we could do something like this:
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index d73d5eaed84..5000906f5f2 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -2823,6 +2823,16 @@ check_substring: if (substring) primary->ts.u.cl = NULL; + if (gfc_peek_ascii_char () == '(') + { + gfc_array_ref arr_ref; + gfc_array_spec *as + = sym->ts.type == BT_CLASS ? CLASS_DATA (sym)->as : sym->as; + gfc_match_array_ref (&arr_ref, as, 0, 0); + + gfc_error_now ("Unexpected array/substring ref at %C"); + return MATCH_ERROR; + } break; case MATCH_NO: It would at least give a better hint. Attached is the patch that adds this to the previous one. Regtests ok on x86_64-pc-linux-gnu / Fedora 39. Is this ok? Regards and thanks for the review, Andre On Tue, 1 Oct 2024 23:31:11 +0200 Harald Anlauf <anl...@gmx.de> wrote: > Hi Andre, > > Am 01.10.24 um 09:43 schrieb Andre Vehreschild: > > Hi all, > > > > this rather old PR reported a parsing bug, when a coarray'ed character > > substring ref is to be parsed, aka CHARACTER(:) :: str[:] ... str(2:5). In > > this case the parser confused the substring ref with an array-ref, because > > an array_spec was present. This patch fixes this by requesting only coarray > > parsing from gfc_match_array_ref when no regular dimension is present. The > > patch is not involved when an array of coarray'ed strings is parsed (that > > worked beforehand). > > while the patch addresses the issue mentioned in the PR, > > > I had to fix the dg-error clauses in the testcase pr102532 because now the > > error of having to many refs is detected by the parsing stage and no longer > > by the resolve stage. It has become a simple syntax error. I hope this is > > ok. > > I find the error messages now less helpful to users: before the patch > we got "Rank mismatch in array reference", which was more suitable > than the newer version with more or less confusing syntax errors. > > I assume you tried to find a better solution - but Intel and NAG > also give syntax errors - so basically I am fine with the patch. > > You may want to wait for a second opinion. If nobody else responds > within the next 2 days, you may proceed nevertheless. > > Thanks, > Harald > > > Regtests ok on x86_64-pc-linux-gnu / Fedora 39. Ok for mainline? > > > > Regards, > > Andre > > -- > > Andre Vehreschild * Email: vehre ad gmx dot de > -- Andre Vehreschild * Email: vehre ad gmx dot de