Bug 81826 - Incorrect handling of directives left by preprocessor
Summary: Incorrect handling of directives left by preprocessor
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-11 16:36 UTC by Raul Laasner
Modified: 2017-08-11 19:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raul Laasner 2017-08-11 16:36:31 UTC
I am trying to compile a preprocessed Fortran source file that contains a syntax error:

  $ cat main.f90 
    implicit none
    a = 5
  end program
  $ gfortran -cpp -E main.f90 -o main.f90.pp.f90
  $ gfortran main.f90.pp.f90 
  main.f90.pp.f90:2:3:

   # 1 "<built-in>"
     1
  Error: Symbol ‘a’ at (1) has no IMPLICIT type

The problem is that the error message refers to the preprocessed file and not the original source file. Also, it is showing an incorrect line above the number "1", which should be the offending line. This is unlike the C compiler:

  $ cat main.c
  int main() // {
    return 0;
  }
  $ gcc -E main.c -o main.c.pp.c
  $ gcc main.c.pp.c 
  main.c: In function ‘main’:
  main.c:2:3: error: expected declaration specifiers before ‘return’
     return 0;
     ^~~~~~
  main.c:3:1: error: expected declaration specifiers before ‘}’ token
   }
   ^
  main.c:3:1: error: expected ‘{’ at end of input

where the error message refers to the correct source file (main.c:2:3).

This issue was brought up at https://gitlab.kitware.com/cmake/cmake/issues/17160#note_301744 and it inhibits the correct behavior of CMake with the Ninja generator.
Comment 1 Andreas Schwab 2017-08-11 16:55:43 UTC
Try adding -fpreprocessed.
Comment 2 Raul Laasner 2017-08-11 19:35:48 UTC
Thank you! This seems to work. Because I had no such issues with ifort, I assumed it was a gfortran bug.