This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch,4.4, Fortran] PR34997 - Better error message for '$' in name
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 20 Feb 2008 15:34:34 +0100
- Subject: [patch,4.4, Fortran] PR34997 - Better error message for '$' in name
Currently, gfortran returns simply MATCH_ERROR in gfc_match_name if a
symbol contains a $ sign. This gives quite unclear error messages:
Error: Syntax error in data declaration at (1)
Error: Expected = sign in PARAMETER statement at (1)
Error: Syntax error in common block name at (1)
The attached patch changes the message to:
Error: Invalid character '$' at (1). Use -fdollar-ok to accept it
which is clearer and points to the -fdollar-ok flag, which is hard to
find otherwise. (Well, I did not find it ;-)
Bootstrapped and regtested (-m32/-m64, gfortran+gomp) on x86-64-linux.
OK for the trunk?
Tobias
2008-02-20 Tobias Burnus <burnus@net-b.de>
PR fortran/34997
* match.c (gfc_match_name): Improve error message for '$'.
2008-02-20 Tobias Burnus <burnus@net-b.de>
PR fortran/34997
* gfortran.dg/dollar_sym_1.f90: New.
* gfortran.dg/dollar_sym_2.f90: New.
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c (revision 132475)
+++ gcc/fortran/match.c (working copy)
@@ -519,6 +519,13 @@ gfc_match_name (char *buffer)
}
while (ISALNUM (c) || c == '_' || (gfc_option.flag_dollar_ok && c == '$'));
+ if (c == '$' && !gfc_option.flag_dollar_ok)
+ {
+ gfc_error ("Invalid character '$' at %C. Use -fdollar-ok to accept it");
+ return MATCH_ERROR;
+ }
+
+
buffer[i] = '\0';
gfc_current_locus = old_loc;
Index: gcc/testsuite/gfortran.dg/dollar_sym_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/dollar_sym_1.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/dollar_sym_1.f90 (revision 0)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/34997
+! Variable names containing $ signs
+!
+ REAL*4 PLT$C_HOUSTPIX ! { dg-error "Invalid character '\\$'" }
+ INTEGER PLT$C_COMMAND ! { dg-error "Invalid character '\\$'" }
+ PARAMETER (PLT$B_OPC=0) ! { dg-error "Invalid character '\\$'" }
+ common /abc$def/ PLT$C_HOUSTPIX, PLT$C_COMMAND ! { dg-error "Invalid character '\\$'" }
+ end
Index: gcc/testsuite/gfortran.dg/dollar_sym_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/dollar_sym_2.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/dollar_sym_2.f90 (revision 0)
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! { dg-options "-fdollar-ok" }
+!
+! PR fortran/34997
+! Variable names containing $ signs
+!
+ REAL*4 PLT$C_HOUSTPIX
+ INTEGER PLT$C_COMMAND
+ PARAMETER (PLT$B_OPC=0)
+ common /abc$def/ PLT$C_HOUSTPIX, PLT$C_COMMAND
+ end