This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch,fortran] PR19261 continuation character illegal as first non-blank character in statement
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 06 Oct 2006 00:01:08 -0700
- Subject: [patch,fortran] PR19261 continuation character illegal as first non-blank character in statement
:ADDPATCH fortran:
The attached patch adds warnings for illegal use of '&' in lines. This follows
from F95 Standard 3.3.1.3. With -pedantic errors are given instead of warnings.
I moved the note about the unavailable error machinery to the top of load_line
since it applies to more than one place in this function.
If someone can figure out how to get that test case to work with the deja-magic,
I would appreciate it. Can't get rid of the excess warnings tests with -S
Regression tested and libgomp tested OK. The libgomp tests require Jacub's
patch that fixes the PR19260 fix breakage.
OK to commit to 4.2?
Regards,
Jerry
2006-10-06 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/19261
* scanner.c (load_line): Add checks for illegal use of '&' and issue
warnings. Issue errors with -pedantic.
Index: scanner.c
===================================================================
*** scanner.c (revision 117424)
--- scanner.c (working copy)
*************** gfc_gobble_whitespace (void)
*** 931,937 ****
In fixed mode, we expand a tab that occurs within the statement
label region to expand to spaces that leave the next character in
the source region.
! load_line returns whether the line was truncated. */
static int
load_line (FILE * input, char **pbuf, int *pbuflen)
--- 931,941 ----
In fixed mode, we expand a tab that occurs within the statement
label region to expand to spaces that leave the next character in
the source region.
! load_line returns whether the line was truncated.
!
! NOTE: The error machinery isn't available at this point, so we can't
! easily report line and column numbers consistent with other
! parts of gfortran. */
static int
load_line (FILE * input, char **pbuf, int *pbuflen)
*************** load_line (FILE * input, char **pbuf, in
*** 939,944 ****
--- 943,949 ----
static int linenum = 0, current_line = 1;
int c, maxlen, i, preprocessor_flag, buflen = *pbuflen;
int trunc_flag = 0, seen_comment = 0;
+ int seen_printable = 0, seen_ampersand = 0;
char *buffer;
/* Determine the maximum allowed line length.
*************** load_line (FILE * input, char **pbuf, in
*** 990,996 ****
if (c == EOF)
break;
if (c == '\n')
! break;
if (c == '\r')
continue; /* Gobble characters. */
--- 995,1014 ----
if (c == EOF)
break;
if (c == '\n')
! {
! /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
! if (gfc_current_form == FORM_FREE
! && !seen_printable && seen_ampersand)
! {
! if (pedantic)
! gfc_error_now
! ("'&' not allowed by itself in line %d", current_line);
! else
! gfc_warning_now
! ("'&' not allowed by itself in line %d", current_line);
! }
! break;
! }
if (c == '\r')
continue; /* Gobble characters. */
*************** load_line (FILE * input, char **pbuf, in
*** 1004,1009 ****
--- 1022,1046 ----
break;
}
+ /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */
+ if (c == '&')
+ seen_ampersand = 1;
+
+ if ((c != ' ' && c != '&' && c != '!') || (c == '!' && !seen_ampersand))
+ seen_printable = 1;
+
+ if (gfc_current_form == FORM_FREE
+ && c == '!' && !seen_printable && seen_ampersand)
+ {
+ if (pedantic)
+ gfc_error_now (
+ "'&' not allowed by itself with comment in line %d", current_line);
+ else
+ gfc_warning_now (
+ "'&' not allowed by itself with comment in line %d", current_line);
+ seen_printable = 1;
+ }
+
/* Is this a fixed-form comment? */
if (gfc_current_form == FORM_FIXED && i == 0
&& (c == '*' || c == 'c' || c == 'd'))
*************** load_line (FILE * input, char **pbuf, in
*** 1011,1019 ****
if (gfc_current_form == FORM_FIXED && c == '\t' && i <= 6)
{
- /* The error machinery isn't available at this point, so we can't
- easily report line and column numbers consistent with other
- parts of gfortran. */
if (!gfc_option.warn_tabs && seen_comment == 0
&& current_line != linenum)
{
--- 1048,1053 ----
! { dg-do compile }
! PR19261 test fix for illegal ampersands in lines.
! Submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
print *, 12345
! & !
print *, 123&
&45
print *, 54321&
& ! { dg-warning "not allowed by itself with comment in line" }
end