public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice
@ 2010-11-29 10:56 mathewc at nag dot co.uk
  2010-11-29 21:02 ` [Bug fortran/46705] " burnus at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: mathewc at nag dot co.uk @ 2010-11-29 10:56 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

           Summary: Spurious "Missing '&' in continued character constant"
                    warning occurs twice
           Product: gcc
           Version: fortran-dev
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mathewc@nag.co.uk


> uname -a
Linux loanamd27 2.6.11.4-20a-smp #1 SMP Wed Mar 23 21:52:37 UTC 2005 x86_64
x86_64 x86_64 GNU/Linux

> gfortran --version
GNU Fortran (GCC) 4.6.0 20101120 (experimental)

> cat contin_char.f90 
1 FORMAT (''&
       )
END

> gfortran -Wampersand contin_char.f90
contin_char.f90:2.8:

       )
        1
Warning: Missing '&' in continued character constant at (1)
contin_char.f90:2.8:

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


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
@ 2010-11-29 21:02 ` burnus at gcc dot gnu.org
  2010-12-08  4:41 ` jvdelisle at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-29 21:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org,
                   |                            |jvdelisle at gcc dot
                   |                            |gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2010-11-29 20:39:24 UTC ---
The crucial part is that a '' or a "" is immediately followed by the ampersand.

The warning is printed by scanner.c's gfc_next_char_literal when called with a
non-zero argument ("in_string"). In io.c, that matches a next_char with
non-zero argument.

The logic fails in io.c with:

static format_token
    ...
    case '\'':
    case '"':
      delim = c;
      ...
      for (;;)
        {
          c = next_char (1); // Reads next second tick: '
          ...
          if (c == delim)
            {
              c = next_char (1); // encounters ampersand and goes into next
line

One might need to do something like (untested!):

              c = next_char (gfc_peek_ascii_char () != '&'));

Or something fancier.


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
  2010-11-29 21:02 ` [Bug fortran/46705] " burnus at gcc dot gnu.org
@ 2010-12-08  4:41 ` jvdelisle at gcc dot gnu.org
  2010-12-11 15:55 ` jvdelisle at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-08  4:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot       |jvdelisle at gcc dot
                   |gnu.org                     |gnu.org

--- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-08 04:40:58 UTC ---
I will work this one.


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
  2010-11-29 21:02 ` [Bug fortran/46705] " burnus at gcc dot gnu.org
  2010-12-08  4:41 ` jvdelisle at gcc dot gnu.org
@ 2010-12-11 15:55 ` jvdelisle at gcc dot gnu.org
  2010-12-11 16:02 ` jvdelisle at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-11 15:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

--- Comment #3 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-11 15:54:38 UTC ---
If you look at the test case you will see that the '&' issue is outside of the
quotes in the format statement.  Right away this told me we should not be
getting the warning at all since it is inside the "in_string" condition in
scanner.c: gfc_next_char_literal.

I found the problem here:

Index: io.c
===================================================================
--- io.c    (revision 167624)
+++ io.c    (working copy)
@@ -383,7 +383,7 @@ format_lex (void)

       if (c == delim)
         {
-          c = next_char (1);
+          c = next_char (0);

           if (c == '\0')
         {

Just above this code in io.c, we have just detected the closing quote so we
should not call next_char with the in_string flag.  I have regression tested
this and all our existing -Wampersand tests still work fine with this change. 
Then we correctly get no warning with the first test case.

Now, if we do this:

1 FORMAT (' &
'  )
END

We get a double warning. I think this is because in the scanner we may scan a
line more than once looking for matches.  I am not decided yet what to do with
this bit.


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
                   ` (2 preceding siblings ...)
  2010-12-11 15:55 ` jvdelisle at gcc dot gnu.org
@ 2010-12-11 16:02 ` jvdelisle at gcc dot gnu.org
  2010-12-11 20:42 ` jvdelisle at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-11 16:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

--- Comment #4 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-11 16:02:51 UTC ---
This appears to resolve the double warning issue.  Regression testing now.

Index: scanner.c
===================================================================
--- scanner.c    (revision 167624)
+++ scanner.c    (working copy)
@@ -1147,7 +1147,7 @@ restart:
       if (in_string)
         {
           if (gfc_option.warn_ampersand)
-        gfc_warning_now ("Missing '&' in continued character "
+        gfc_warning ("Missing '&' in continued character "
                  "constant at %C");
           gfc_current_locus.nextc--;
         }


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
                   ` (3 preceding siblings ...)
  2010-12-11 16:02 ` jvdelisle at gcc dot gnu.org
@ 2010-12-11 20:42 ` jvdelisle at gcc dot gnu.org
  2010-12-11 23:15 ` jvdelisle at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-11 20:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-11 20:41:52 UTC ---
I think this does the trick for the original and a few variations.  I would
like to use an enumerator rather than 0 , 1, and 2 for the in_string flag. 
That will touch a few more places, but will make the code more readable.

Index: scanner.c
===================================================================
--- scanner.c    (revision 167711)
+++ scanner.c    (working copy)
@@ -1146,10 +1146,10 @@ restart:
     {
       if (in_string)
         {
-          if (gfc_option.warn_ampersand)
-        gfc_warning_now ("Missing '&' in continued character "
-                 "constant at %C");
           gfc_current_locus.nextc--;
+          if (gfc_option.warn_ampersand && in_string == 1)
+        gfc_warning ("Missing '&' in continued character "
+                 "constant at %C");
         }
       /* Both !$omp and !$ -fopenmp continuation lines have & on the
          continuation line only optionally.  */
Index: io.c
===================================================================
--- io.c    (revision 167711)
+++ io.c    (working copy)
@@ -383,7 +383,7 @@ format_lex (void)

       if (c == delim)
         {
-          c = next_char (1);
+          c = next_char (2);

           if (c == '\0')
         {


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
                   ` (4 preceding siblings ...)
  2010-12-11 20:42 ` jvdelisle at gcc dot gnu.org
@ 2010-12-11 23:15 ` jvdelisle at gcc dot gnu.org
  2010-12-11 23:26 ` jvdelisle at gcc dot gnu.org
  2010-12-11 23:34 ` jvdelisle at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-11 23:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

--- Comment #6 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-11 23:14:48 UTC ---
Author: jvdelisle
Date: Sat Dec 11 23:14:45 2010
New Revision: 167716

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167716
Log:
2010-12-11  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

    PR fortran/46705
    * gfortran.h: New enum gfc_instring.
    (gfc_next_char_literal): Update prototype.
    * scanner.c (gfc_next_char_literal): Use new enum. Only give missing
    '&' warning for INSTRING_WARN. (gfc_next_char): Use new enum.
    (gfc_gobble_whitespace): Likewise.
    * io.c (next_char): Use new enum. (next_char_not_space): Likewise.
    (format_lex): Likewise.
    * match.c (gfc_match_parens): Likewise.
    (gfc_match_special_char): Likewise. (gfc_match_name_C): Likewise.
    * parse.c (next_fixed): Likewise.
    * primary.c (match_hollerith_constant): Likewise.
    (next_string_char): Likewise.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/io.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/scanner.c


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
                   ` (5 preceding siblings ...)
  2010-12-11 23:15 ` jvdelisle at gcc dot gnu.org
@ 2010-12-11 23:26 ` jvdelisle at gcc dot gnu.org
  2010-12-11 23:34 ` jvdelisle at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-11 23:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

--- Comment #7 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-11 23:26:11 UTC ---
Author: jvdelisle
Date: Sat Dec 11 23:26:07 2010
New Revision: 167717

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167717
Log:
2010-12-11  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

    PR fortran/46705
    * gfortran.dg/continuation_12.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/continuation_12.f90
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/46705] Spurious "Missing '&' in continued character constant" warning occurs twice
  2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
                   ` (6 preceding siblings ...)
  2010-12-11 23:26 ` jvdelisle at gcc dot gnu.org
@ 2010-12-11 23:34 ` jvdelisle at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2010-12-11 23:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46705

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED

--- Comment #8 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> 2010-12-11 23:34:16 UTC ---
Closing, no backport.


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

end of thread, other threads:[~2010-12-11 23:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-29 10:56 [Bug fortran/46705] New: Spurious "Missing '&' in continued character constant" warning occurs twice mathewc at nag dot co.uk
2010-11-29 21:02 ` [Bug fortran/46705] " burnus at gcc dot gnu.org
2010-12-08  4:41 ` jvdelisle at gcc dot gnu.org
2010-12-11 15:55 ` jvdelisle at gcc dot gnu.org
2010-12-11 16:02 ` jvdelisle at gcc dot gnu.org
2010-12-11 20:42 ` jvdelisle at gcc dot gnu.org
2010-12-11 23:15 ` jvdelisle at gcc dot gnu.org
2010-12-11 23:26 ` jvdelisle at gcc dot gnu.org
2010-12-11 23:34 ` jvdelisle at gcc dot gnu.org

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).