Bug 29671 - preprocessor statements must start in column 1
Summary: preprocessor statements must start in column 1
Status: RESOLVED DUPLICATE of bug 28662
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
Depends on:
Reported: 2006-10-31 11:42 UTC by Daniel Franke
Modified: 2012-03-03 14:36 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2006-10-31 13:02:35


Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Franke 2006-10-31 11:42:46 UTC
Preprocessor statements (as if|else|endif|error|warning) must start in colum 1, otherwise gfortran tries to handle them itself?!

$> cat pp.F90
PROGRAM test_preprocessor
 #error "EEE"         ! whitespace is significant

$> gfortran-4.3 -g -Wall pp.F90
 In file pp.F90:3

 #error "EEE"
Error: Unclassifiable statement at (1)

$> cat pp.F90
PROGRAM test_preprocessor
#error "EEE"

$> gfortran-4.3 -g -Wall pp.F90
pp.F90:3: error: #error "EEE"

Filed this as fortran report since gcc bails out as expected and both run (afaik) the same preprocessor:

$> cat pp.c
int main() {
  #error "EEE"     /* whitespaces are not significant */
  return 0;

$> gcc-svn -g -Wall pp.c
pp.c:2:4: error: #error "EEE"

$> gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../svn/gcc/configure --prefix=/home/daniel/nfs/packages/i686-pc-linux-gnu/gcc-svn --disable-nls --enable-threads=posix --enable-shared --enable-bootstrap --with-system-zlib --program-suffix=-svn --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.3.0 20061030 (experimental)
Comment 1 Tobias Burnus 2006-10-31 12:48:40 UTC
The problem is that gfortran calls "cpp" with the -traditional-cpp option.

This causes some more modern constructs not to work and it also is the reason behind your problem. (cf. PR 28662).

We need to use -traditional-cpp since "some tokens in C are not
tokens in Fortran so you could get the wrong result." (A.P. in the other PR)

The solution is to modify cpp to know fortran tokens (when called with -lang-fortran).

Note this problem is not limited to gfortran; e.g. the NAG f95 compiler uses Sun's public-domain fpp (netlib.org/fortran/), which has similar problems.
Comment 2 Tobias Burnus 2006-10-31 13:02:35 UTC
Confirm and mark as enhancement.
Comment 3 Francois-Xavier Coudert 2012-03-03 14:36:27 UTC
Fixed as duplicate of PR28662, as both have the same root cause.

*** This bug has been marked as a duplicate of bug 28662 ***