]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/42852 (gfortran -Wall warns about truncated lines when only a continuat...
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 25 Jul 2010 15:07:45 +0000 (15:07 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Sun, 25 Jul 2010 15:07:45 +0000 (15:07 +0000)
2010-07-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR fortran/42852
* scanner.c (gfc_next_char_literal): Move check for truncation earlier
in the function so that it does not get missed by early exits.
(load_line): Add checks for quoted strings and free form comments to
disable warnings on comments. Add check for ampersand as first
character after truncation and don't warn for this case, but warn if
there are subsequent non-whitespace characters.

From-SVN: r162512

gcc/fortran/ChangeLog
gcc/fortran/scanner.c

index 6f654cafa4c8336e69293ef4c34d19cfe61c51be..3627b9e1b4a98e5cc02d38f67a87c3a6d2ee8bd2 100644 (file)
@@ -1,3 +1,13 @@
+2010-07-25  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR fortran/42852
+       * scanner.c (gfc_next_char_literal): Move check for truncation earlier
+       in the function so that it does not get missed by early exits.
+       (load_line): Add checks for quoted strings and free form comments to
+       disable warnings on comments. Add check for ampersand as first
+       character after truncation and don't warn for this case, but warn if
+       there are subsequent non-whitespace characters.
+
 2010-07-24  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/40011
index a8ab2353e8581f44d5673c21dff88b760fa3850c..acc2f5a770853aed5323e462102070d58213a909 100644 (file)
@@ -1044,6 +1044,17 @@ restart:
          goto done;
        }
 
+      /* Check to see if the continuation line was truncated.  */
+      if (gfc_option.warn_line_truncation && gfc_current_locus.lb != NULL
+         && gfc_current_locus.lb->truncated)
+       {
+         int maxlen = gfc_option.free_line_length;
+         gfc_current_locus.lb->truncated = 0;
+         gfc_current_locus.nextc += maxlen;
+         gfc_warning_now ("Line truncated at %L", &gfc_current_locus);
+         gfc_current_locus.nextc -= maxlen;
+       }
+
       if (c != '&')
        goto done;
 
@@ -1095,17 +1106,6 @@ restart:
            }
        }
 
-      /* Check to see if the continuation line was truncated.  */
-      if (gfc_option.warn_line_truncation && gfc_current_locus.lb != NULL
-         && gfc_current_locus.lb->truncated)
-       {
-         int maxlen = gfc_option.free_line_length;
-         gfc_current_locus.lb->truncated = 0;
-         gfc_current_locus.nextc += maxlen;
-         gfc_warning_now ("Line truncated at %L", &gfc_current_locus);
-         gfc_current_locus.nextc -= maxlen;
-       }
-
       /* Now find where it continues. First eat any comment lines.  */
       openmp_cond_flag = skip_free_comments ();
 
@@ -1420,7 +1420,7 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pbuflen, const int *first_char)
   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;
+  int seen_printable = 0, seen_ampersand = 0, quoted = ' ';
   gfc_char_t *buffer;
   bool found_tab = false;
 
@@ -1502,6 +1502,18 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pbuflen, const int *first_char)
          && (c == '*' || c == 'c' || c == 'd'))
        seen_comment = 1;
 
+      if (quoted == ' ')
+       {
+         if (c == '\'' || c == '"')
+           quoted = c;
+       }
+      else if (c == quoted)
+       quoted = ' ';
+
+      /* Is this a free-form comment?  */
+      if (c == '!' && quoted == ' ')
+        seen_comment = 1;
+
       /* Vendor extension: "<tab>1" marks a continuation line.  */
       if (found_tab)
        {
@@ -1550,17 +1562,33 @@ load_line (FILE *input, gfc_char_t **pbuf, int *pbuflen, const int *first_char)
        }
       else if (i >= maxlen)
        {
+         bool trunc_warn = true;
+
+         /* Enhancement, if the very next non-space character is an ampersand
+            or comment that we would otherwise warn about, don't mark as
+            truncated.  */
+
          /* Truncate the rest of the line.  */
          for (;;)
            {
              c = getc (input);
-             if (c == '\r')
+             if (c == '\r' || c == ' ')
                continue;
 
              if (c == '\n' || c == EOF)
                break;
 
-             trunc_flag = 1;
+             if (!trunc_warn && c != '!')
+               trunc_warn = true;
+
+             if (trunc_warn && (c == '&' || c == '!'))
+               trunc_warn = false;
+
+             if (c == '!')
+               seen_comment = 1;
+
+             if (trunc_warn && !seen_comment)
+               trunc_flag = 1;
            }
 
          c = '\n';