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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-04-23 
08:27:05 UTC ---
> Hmm... apparently the PGI compiler uses the same rule for enabling
> preprocessor with .f and .F extensions.

I think most compilers follow that pattern, which can be overridden by "-cpp"
and "-no-cpp", respectively.


> Then, if there's some important reason behind it (?)

Well, the C preprocessor is not part of the Fortran standard, thus, a compiler
can expect that no C preprocessing has to be done. (Though, most compilers do
support CPP preprocessing; there are some caveats with regards to newer CPP
features: The preprocessor has then to be aware of Fortran. Thus, many
compilers do not support the CPP of newer C standards.)

Side note: The Fortran 95 standard actually defines in Part 3 "Conditional
Compilation" (ISO/IEC 1539-3:1998), however, this Fortran-specific way was
never widely used and it is not implemented in any compiler (to my knowledge).
However, there exists a preprocessor "coco" (written in Fortran).


> perhaps at least the warning message could be improved by indicating that the
> preprocessor is off.

I concur.


Untested patch.

Remark: At some point, gfortran needs to follow GCC with regards to
-f(no-)diagnostics-show-caret. I now keep the "<file>:<line>:" with -cpp but
the caret diagnostic without.

--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -1792,4 +1792,9 @@ preprocessor_line (gfc_char_t *c)
  bad_cpp_line:
-  gfc_warning_now ("%s:%d: Illegal preprocessor directive",
-                  current_file->filename, current_file->line);
+  if (gfc_cpp_enabled ())
+    gfc_warning_now ("%s:%d: Illegal preprocessor directive",
+                    current_file->filename, current_file->line);
+  else
+    gfc_warning_now ("Ignoring preprocessor directive at %C. Used -cpp to ",
+                    "enable the C preprocessor");
+
   current_file->line++;(In reply to comment #2)

Reply via email to