rui314 / chibicc

A small C compiler
MIT License
9.57k stars 871 forks source link

#include errors are reported on the wrong line #12

Closed joefarebrother closed 3 years ago

joefarebrother commented 3 years ago

The following file:

#include "fake.h"

int main() {}

where fake.h does not exist produces the output

fail_include.c:3: int main() {}
                  ^ fake.h: cannot open file: No such file or directory

whereas the error should instead be reported on the #include line.

rui314 commented 3 years ago

It looks like #include error is reported against the next token of the #include line. That's not a severe error but certainly confusing. Thank you for reporting.

rui314 commented 3 years ago

This problem has been fixed. Now chibicc prints out an error message in the following way.

/tmp/foo.c:1: #include "foo"
                       ^ foo: cannot open file: No such file or directory