Bug 30968 - [4.1 only] Bogus warning with continued lines of concatenated strings
Summary: [4.1 only] Bogus warning with continued lines of concatenated strings
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Tobias Burnus
URL:
Keywords: diagnostic, rejects-valid
Depends on:
Blocks:
 
Reported: 2007-02-26 13:11 UTC by Harald Anlauf
Modified: 2007-03-05 12:59 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-02-27 15:36:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2007-02-26 13:11:16 UTC
The following program gives a bogus warning when
compiled with -Wall or -std=f95 or -std=f2003:


program gfcbug59
  print *, "Hello"&
       // " World"      ! Bogus warning with -Wall or -std=f95 or -std=f2003
end program gfcbug59

% gfc -Wall gfcbug59.f90
gfcbug59.f90:3.8:

       // " World"      ! Bogus warning with -Wall or -std=f95 or -std=f2003
       1
Warning: Missing '&' in continued character constant at (1)
gfcbug59.f90:3.8:

       // " World"      ! Bogus warning with -Wall or -std=f95 or -std=f2003
       1
Warning: Missing '&' in continued character constant at (1)
Comment 1 Tobias Burnus 2007-02-26 17:11:29 UTC
Confirmed.

One needs the second "&" for:
 "Hello&
   & World"

But one does not need it for:
 "Hello" &
 , "World"

The following seems to be a gfortran/ifort extension:
  "Hello&
   World"
For this case, the warning / std error is correct.

The bug in gfortran is that  "Hello" &   is correctly seen as non-character context whereas   "Hello" &  is wrongly regarded as character context.
Comment 2 Tobias Burnus 2007-02-26 17:39:05 UTC
> The bug in gfortran is that  "Hello" &   is correctly seen as non-character
> context whereas   "Hello" &  is wrongly regarded as character context.
The last line should be:   "Hello"&   without space between " and &.

Note: Printing an error twice is also a bug.
Comment 3 Tobias Burnus 2007-02-26 20:17:58 UTC
Patch.

Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c       (Revision 122328)
+++ gcc/fortran/primary.c       (Arbeitskopie)
@@ -773,7 +773,7 @@
     return c;

   old_locus = gfc_current_locus;
-  c = gfc_next_char_literal (1);
+  c = gfc_next_char_literal (0);

   if (c == delimiter)
     return c;
@@ -852,7 +852,7 @@
 match_string_constant (gfc_expr **result)
 {
   char *p, name[GFC_MAX_SYMBOL_LEN + 1];
-  int i, c, kind, length, delimiter;
+  int i, c, kind, length, delimiter, warn_ampersand;
   locus old_locus, start_locus;
   gfc_symbol *sym;
   gfc_expr *e;
@@ -979,10 +979,16 @@
   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");
+
   if (next_string_char (delimiter) != -1)
     gfc_internal_error ("match_string_constant(): Delimiter not found");
Comment 4 Tobias Burnus 2007-02-28 08:04:08 UTC
Subject: Bug 30968

Author: burnus
Date: Wed Feb 28 08:03:47 2007
New Revision: 122401

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122401
Log:
2007-02-28  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-28  Tobias Burnus  <burnus@net-b.de>

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


Added:
    trunk/gcc/testsuite/gfortran.dg/continuation_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Tobias Burnus 2007-03-05 12:58:28 UTC
Subject: Bug 30968

Author: burnus
Date: Mon Mar  5 12:58:14 2007
New Revision: 122547

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122547
Log:
2007-03-05  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-03-05  Tobias Burnus  <burnus@net-b.de>

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


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/continuation_7.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/primary.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 6 Tobias Burnus 2007-03-05 12:59:47 UTC
Fixed in 4.2 (and 4.3). I don't think it is worth to porting to 4.1.
-> close bug.