public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] Fix bogus warning with continued lines
@ 2007-02-27 17:57 Tobias Burnus
  2007-02-28 11:10 ` Jerry DeLisle
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2007-02-27 17:57 UTC (permalink / raw)
  To: gcc-patches, 'fortran@gcc.gnu.org'

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

:ADDPATCH fortran:

Fortran allows strings to continue by placing a & as last character in
the line:

print *, "Hello&
   & World"

gfortran supports as extension:

print *, "Hello&
     World"

With either -Wall, -pedantic or -std=f95/f2003 the following error is shown:

Warning: Missing '&' in continued character constant at (1)

However, the same message is (wrongly) shown for

print *, "Hello"&
    , " World"&
    // "!"

The problem is that next_string_char read the " and needs to read the
next character to check it is not another ". It erroneously calls 
gfc_next_char_literal  with the option in_string = 1, which causes it to
read up to the comma or slash.

The following patch corrects this and ensures also that the warning
message is printed only once.

Thanks to Harald Anlauf for the report.

Bootstrapped and regression tested on x86-64/Linux.
Ok for the trunk and 4.2? (As it is only a warning, I think we can omit
4.1.)

Tobias

[-- Attachment #2: continuation.diff --]
[-- Type: text/x-patch, Size: 2861 bytes --]

2007-02-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/30968
	* primary.c (next_string_char): Correct reading a character
	after the delimiter.
	(match_string_constant): Print warning message only once.

2007-02-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/30968
	* gfortran.dg/continuation_7.f90: New test.

Index: gcc/fortran/primary.c
===================================================================
*** gcc/fortran/primary.c	(revision 122377)
--- gcc/fortran/primary.c	(working copy)
*************** next_string_char (char delimiter)
*** 773,779 ****
      return c;
  
    old_locus = gfc_current_locus;
!   c = gfc_next_char_literal (1);
  
    if (c == delimiter)
      return c;
--- 773,779 ----
      return c;
  
    old_locus = gfc_current_locus;
!   c = gfc_next_char_literal (0);
  
    if (c == delimiter)
      return c;
*************** static match
*** 852,858 ****
  match_string_constant (gfc_expr **result)
  {
    char *p, name[GFC_MAX_SYMBOL_LEN + 1];
!   int i, c, kind, length, delimiter;
    locus old_locus, start_locus;
    gfc_symbol *sym;
    gfc_expr *e;
--- 852,858 ----
  match_string_constant (gfc_expr **result)
  {
    char *p, name[GFC_MAX_SYMBOL_LEN + 1];
!   int i, c, kind, length, delimiter, warn_ampersand;
    locus old_locus, start_locus;
    gfc_symbol *sym;
    gfc_expr *e;
*************** got_delim:
*** 979,988 ****
--- 979,994 ----
    gfc_current_locus = start_locus;
    gfc_next_char ();		/* Skip delimiter */
  
+   /* We disable the warning for the following loop as the warning has already
+      been printed in the loop above.  */
+   warn_ampersand = gfc_option.warn_ampersand;
+   gfc_option.warn_ampersand = 0;
+ 
    for (i = 0; i < length; i++)
      *p++ = next_string_char (delimiter);
  
    *p = '\0';	/* TODO: C-style string is for development/debug purposes.  */
+   gfc_option.warn_ampersand = warn_ampersand;
  
    if (next_string_char (delimiter) != -1)
      gfc_internal_error ("match_string_constant(): Delimiter not found");
Index: gcc/testsuite/gfortran.dg/continuation_7.f90
===================================================================
*** gcc/testsuite/gfortran.dg/continuation_7.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/continuation_7.f90	(revision 0)
***************
*** 0 ****
--- 1,22 ----
+ ! { dg-do "compile" }
+ ! { dg-options "-Wall -std=f95" }
+ ! There should only two warnings be printed.
+ ! PR fortran/30968
+ print *, "Foo bar&
+         &Bar foo"
+ print *, "Foo bar&
+         Bar foo" ! { dg-warning "Missing '&' in continued character constant" }
+ print *, "Foo bar"&
+         &, "Bar foo"
+ print *, "Foo bar"&
+         , "Bar foo"
+ 
+ print '(&
+     a)', 'Hello' ! { dg-warning "Missing '&' in continued character constant" }
+ print '(&
+    &a)', 'Hello'
+ print '('&
+    &//'a)', 'Hello'
+ print '('&
+    // "a)", 'Hello'
+ end

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch, fortran] Fix bogus warning with continued lines
  2007-02-27 17:57 [Patch, fortran] Fix bogus warning with continued lines Tobias Burnus
@ 2007-02-28 11:10 ` Jerry DeLisle
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2007-02-28 11:10 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

Tobias Burnus wrote:
> :ADDPATCH fortran:
> 
> Fortran allows strings to continue by placing a & as last character in
> the line:
> 
> print *, "Hello&
>    & World"
> 
> gfortran supports as extension:
> 
> print *, "Hello&
>      World"
> 
> With either -Wall, -pedantic or -std=f95/f2003 the following error is shown:
> 
> Warning: Missing '&' in continued character constant at (1)
> 
> However, the same message is (wrongly) shown for
> 
> print *, "Hello"&
>     , " World"&
>     // "!"
> 
> The problem is that next_string_char read the " and needs to read the
> next character to check it is not another ". It erroneously calls 
> gfc_next_char_literal  with the option in_string = 1, which causes it to
> read up to the comma or slash.
> 
> The following patch corrects this and ensures also that the warning
> message is printed only once.
> 
> Thanks to Harald Anlauf for the report.
> 
> Bootstrapped and regression tested on x86-64/Linux.
> Ok for the trunk and 4.2? (As it is only a warning, I think we can omit
> 4.1.)

This is OK,

Jerry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-28  1:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-27 17:57 [Patch, fortran] Fix bogus warning with continued lines Tobias Burnus
2007-02-28 11:10 ` Jerry DeLisle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).