Bug 34203 - Treat \ as normal character (at least on Windows); diagnose unrecognized escape characters
Summary: Treat \ as normal character (at least on Windows); diagnose unrecognized esca...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-11-23 08:54 UTC by Tobias Burnus
Modified: 2007-12-18 22:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-25 03:11:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-11-23 08:54:51 UTC
Currently, \ are treated by default as C-style escape characters with some special treatment to allow   foo = "\"  

At least for Windows paths, the result of path = 'c:\windows\somewhere\big.txt' is surprising as the \w remains but the \b is replaced.

I believe one should give a warning that \w does not match anything. 

Additionally, we should consider to default to -fbackslash - at least on Windows. Note additionally that "\" belongs to Fortran 2003 standard Fortran character set. Currently we offer:

-fno-backslash
    Change the interpretation of backslashes in string literals from "C-style" 
    escape characters to a single backslash character.

From the thread at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/c8dd08d6da052499/

Remark by Richard Maine:

Well, in f0003, backslash is part of the standard Fortran character set.
So I'll find it awfully hard to accept as reasonable a default that
doesn't conform to the standard. But then I'm one of those who has
always thought that doing backslash processing on Fortan code was an
unreasonable default, so just consider me biased. 

Remark by James Van Buskirk:

Andy was kind enough to change the default to -fno-backslash for
Windows g95, following the logic that it's quite common to want to
specify paths with embedded backslashes on that platform.  The
C escape sequences are mostly just an annoyance to be worked around
for Fortran programmers.  As a C programmer writing a Fortran
compiler it may not always be apparent how confusing and error-prone
the C way of doing things is (to a Fortran programmer) but it is as
bad as that and worse.  Same goes for internal representations of
LOGICAL variables.
Comment 1 kargls 2007-11-23 16:26:53 UTC
As I've stated before, I think putting machine dependent code
into the Fortran frontend is a bad idea.  You'll soon see a
tangled mess of #ifdef ... #else ... #endif code, which will
become difficult to maintain.

gfortran's default behavior should match whatever g77 did
with C escape sequences.
Comment 2 Janne Blomqvist 2007-11-23 19:05:34 UTC
IMHO F2003 compatibility is be more important than g77 compatibility, so I would be ok with making -fno-backslash the default. That being said, at the very least -fno-backslash should be enabled with -std=f2003.

Though I agree with Steve that platform-specific behaviour should be avoided. Not only #ifdefs, but it might also confuse multiplatform users .
Comment 3 kargls 2007-11-23 19:29:04 UTC
(In reply to comment #1)
> 
> gfortran's default behavior should match whatever g77 did
> with C escape sequences.
> 

Found it.

http://gcc.gnu.org/onlinedocs/gcc-3.3.6/g77/Backslash-in-Constants.html#Backslash-in-Constants

Note, I'm not emotional attached to Craig's decision with g77, and in fact,
one might argue that Craig's argument has diminished with age.  UNIX f77 has
been dead for a long time.
Comment 4 Jerry DeLisle 2007-11-23 22:16:04 UTC
I think that future standard compliance is important so I move that we make -fno-backslash the default behavior.

I also agree that if backslash is enabled that we issue a runtime warning for situations like \w.
Comment 5 Thomas Koenig 2007-11-24 19:45:58 UTC
(In reply to comment #4)
> I think that future standard compliance is important so I move that we make
> -fno-backslash the default behavior.

Agreed.

Is this still in time for 4.3?  If we make that change, it's probably
better for 4.3 than for 4.4.

> I also agree that if backslash is enabled that we issue a runtime warning for
> situations like \w.

What about \w ?

Comment 6 Andrew Pinski 2007-11-25 03:11:02 UTC
Confirmed.
Comment 7 Tobias Burnus 2007-11-26 22:14:29 UTC
Subject: Bug 34203

Author: burnus
Date: Mon Nov 26 22:14:20 2007
New Revision: 130451

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130451
Log:
2007-11-26  Steven G. Kargl  <kargls@comcast.net>

        * options.c:  Change default behavior of backslash processing.
        * invoke.texi: Update documentation.

2007-11-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34203
        * gfortran.dg/backslash_3.f: Add -fbackslash option.
        * gfortran.dg/init_flag_1.f90: Add -fbackslash option.
        * gfortran.dg/backslash_1.f90: Remove no longer needed
        -fno-backslash option.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/invoke.texi
    trunk/gcc/fortran/options.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/backslash_1.f90
    trunk/gcc/testsuite/gfortran.dg/backslash_3.f
    trunk/gcc/testsuite/gfortran.dg/init_flag_1.f90

Comment 8 Tobias Burnus 2007-11-26 22:54:00 UTC
I just committed Steve's patch. Now gfortran uses -fno-backslash by default.

Now we only need to improve the warning:

For C gcc warns for:

  char c[] = "\w";

a.c:3:14: warning: unknown escape sequence '\w'

gfortran should do likewise in match.c's gfc_match_special_char. Actually, we do not fully support all C escape sequences (see "5.2.2 Character display semantics", "6.4.4.4 Character constants" and "6.4.3 Universal character names"); missing are:

- trigraphs (I don't think anyone misses them)
- \" and \'  (use "" or '' instead)
- \?  (use ?)
- \o, \oo \ooo  (o = octal digit) - except of \0
- \xh, \xhh (h = hexadecimal digit)
- \uhhhh, \Uhhhhhhhh (h = hexadecimal digit)

I don't know whether we really need to implement them, but at least we should document what we have. A proper documentation would be something like Intel's
http://www.intel.com/software/products/compilers/docs/flin/main_for/index.htm
Comment 9 kargls 2007-11-26 23:21:41 UTC
(In reply to comment #8)
> I just committed Steve's patch. Now gfortran uses -fno-backslash by default.
> 
> Now we only need to improve the warning:
> 
> For C gcc warns for:
> 
>   char c[] = "\w";
> 
> a.c:3:14: warning: unknown escape sequence '\w'
> 

Tobias, 

I think that gfortran should not bother with a warning.
A better solution would be to simply list the escape 
sequences that -fbackslash trigger, and state the
all other combinations are not expanded.

I think gfortran definitely wants to avoid the pandora's box
of trigraph, octal, and hexidecimal escaped character sequences.

The following was tested with a "make pdf"

Index: invoke.texi
===================================================================
--- invoke.texi (revision 130454)
+++ invoke.texi (working copy)
@@ -239,6 +239,11 @@ Allow @samp{$} as a valid character in a
 @cindex escape characters
 Change the interpretation of backslashes in string literals
 from a single backslash character to ``C-style'' escape characters.
+The following combinations are expanded \a, \b, \f, \n, \r, \t,
+\v, \\, and \0 to the ASCII characters alert, backspace, form feed,
+newline, carriage return, horizontal tab, vertical tab, backslash,
+and NUL, respectively.  All other combinations of a character preceded
+by \ are unexpanded.
 
 @item -fmodule-private
 @opindex @code{fmodule-private}


Comment 10 Jerry DeLisle 2007-11-30 04:11:02 UTC
Subject: Bug 34203

Author: jvdelisle
Date: Fri Nov 30 04:10:47 2007
New Revision: 130530

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130530
Log:
2007-11-29  Steven G. Kargl  <kargls@comcast.net>

	PR fortran/34230
	* fortran/arith.c (gfc_check_real_range): Set intermediate values
	to +-Inf and 0 when -fno-range-check is in effect.
	* fortran/invoke.texi: Improve -fno-range-check description.

	PR fortran/34203
	* fortran/invoke.texi: Document the C escaped characters activated
	by -fbackslash.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/invoke.texi

Comment 11 Thomas Koenig 2007-12-18 22:27:54 UTC
This is fixed on trunk, isn't it?

Closing.