[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 Dominique d'Humieres changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|--- |FIXED --- Comment #8 from Dominique d'Humieres --- This is fixed since at least GCC7.
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 --- Comment #7 from dominiq at gcc dot gnu.org --- Author: dominiq Date: Wed May 1 17:40:22 2019 New Revision: 270776 URL: https://gcc.gnu.org/viewcvs?rev=270776&root=gcc&view=rev Log: 2019-05-01 Dominique d'Humieres PR fortran/60144 * match.c (gfc_match_parens): Change the location for missing ')'. (gfc_match_if): Detect a missing '('. Remove the spurious named constant error. Change the wording of some errors. (gfc_match_else): Change the wording of an error. (gfc_match_elseif): Detect a missing '('. Improve the matching process to get a better syntax analysis. PR fortran/60144 * gfortran.dg/block_name_2.f90: Adjust dg-error. * gfortran.dg/dec_type_print_3.f90.f90: Likewise * gfortran.dg/pr60144.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/pr60144.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/match.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/block_name_2.f90 trunk/gcc/testsuite/gfortran.dg/dec_type_print_3.f90
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 --- Comment #6 from Dominique d'Humieres --- I don't understand the goal of the block (line 1651 of gcc/fortran/match.c) /* The gfc_match_assignment() above may have returned a MATCH_NO where the assignment was to a named constant. Check that special case here. */ m = gfc_match_assignment (); if (m == MATCH_NO) { gfc_error ("Cannot assign to a named constant at %C"); gfc_free_expr (expr); gfc_undo_symbols (); gfc_current_locus = old_loc; return MATCH_ERROR; } The closest test matching my understanding of the comment is integer, parameter :: i = 1 if (i == 2) i = 3 ! { dg-error "in variable definition context" } end which gives the following error if_param.f90:2:12: 2 | if (i == 2) i = 3 ! { dg-error "in variable definition context" } |1 Error: Named constant 'i' in variable definition context (assignment) at (1) If I remove the block, I get the following errors for the test in comment 0: pr60144.f90:2:15: 2 | if (.TRUE.) | 1 Error: Unclassifiable statement in IF-clause at (1) pr60144.f90:3:11: 3 | else if (.FALSE.) | 1 Error: Unexpected junk after ELSE statement at (1) which looks better for the IF statement. For the ELSE IF error, how can I move the caret after '(.FALSE.)' and replace 'junk' with something neutral (token, statement, ...)?
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 Dominique d'Humieres changed: What|Removed |Added Status|NEW |WAITING --- Comment #5 from Dominique d'Humieres --- > Error messages: > -- > if.F90:2.15: > > if (.TRUE.) >1 > Error: Cannot assign to a named constant at (1) > if.F90:3.11: > > else if (.FALSE.) >1 > Error: Unexpected junk after ELSE statement at (1) > [...] > -- > > Both errors should read something like "Missing THEN after IF/ELSE IF". > > The first error message doesn't even make sense... % gfc dec_type_print_red.f90 dec_type_print_red.f90:20:11: 20 | if (b) type*,a(i) ! test TYPE as PRINT inside one-line IF | 1 Error: Cannot assign to a named constant at (1) (from gfortran.dg/dec_type_print.f90 compiled without the -fdec option). IMO replacing "Cannot assign to a named constant" with "Syntax error" will give an immediate clue of what is wrong. A longer alternative could be something such as ""Syntax error, missing or bad STATEMENT".
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 Dominique d'Humieres changed: What|Removed |Added Priority|P3 |P5 Severity|minor |enhancement
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 Dominique d'Humieres changed: What|Removed |Added CC||Joost.VandeVondele at mat dot ethz ||.ch --- Comment #4 from Dominique d'Humieres --- *** Bug 38303 has been marked as a duplicate of this bug. ***
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 Dominique d'Humieres changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2014-02-11 Ever confirmed|0 |1 --- Comment #3 from Dominique d'Humieres --- Confirmed on 4.7.4, 4.8.3, and trunk (4.9). Related to pr32151.
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 --- Comment #2 from Sergio Losilla --- (In reply to kargl from comment #1) > How is the compiler suppose to know that the programmer may have > meant > >program ifelif >if (.TRUE.) i = 42 >if (.FALSE.) then > j = 42 >end if >end program As far as I know, there are two possible statements starting with if: if () then if () The compiler should recognize that *something* is missing, be it either a then or a statement. > As for the message that you think makes no sense, I suspect > the parse has identified (.TRUE.) as a malformed expression. Well, the message objectively makes no sense because there is no assignment whatsoever. At the very least, the message is confusing.
[Bug fortran/60144] Misleading error message when missing "then" after "if" and "else if"
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60144 kargl at gcc dot gnu.org changed: What|Removed |Added CC||kargl at gcc dot gnu.org --- Comment #1 from kargl at gcc dot gnu.org --- (In reply to Sergio Losilla from comment #0) > Compiler version: > GNU Fortran (Ubuntu 20130917-1ubuntu1) 4.9.0 20130917 (experimental) [trunk > revision 202647] > > Test program: > > program ifelif > if (.TRUE.) > else if (.FALSE.) > end if > end program > > > Error messages: > -- > if.F90:2.15: > > if (.TRUE.) >1 > Error: Cannot assign to a named constant at (1) > if.F90:3.11: > > else if (.FALSE.) >1 > Error: Unexpected junk after ELSE statement at (1) > [...] > -- > > Both errors should read something like "Missing THEN after IF/ELSE IF". > > The first error message doesn't even make sense... How is the compiler suppose to know that the programmer may have meant program ifelif if (.TRUE.) i = 42 if (.FALSE.) then j = 42 end if end program As for the message that you think makes no sense, I suspect the parse has identified (.TRUE.) as a malformed expression.