cc65 / cc65

cc65 - a freeware C compiler for 6502 based systems

Home Page:https://cc65.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cc65: Error reporting is broken (again)

kugelfuhr opened this issue · comments

Using the current version:

#include <stdlib.h>
typedef int boolean;
#define NULL            0
void Func1()
{
}
extern boolean Func2();

Results in:

test.c:3: Error: Macro redefinition is not identical
test.c:7: Warning: Implicit 'int' is an obsolete feature
test.c:7: Error: ',' or ';' expected after top level declarator
2 errors and 1 warnings generated.

The error in line 3 is ok, but what the heck do the errors for line 7 mean? There's nothing wrong in this line.

The funny thing is, if line 3 is commented out:

#include <stdlib.h>
typedef int boolean;
//#define NULL            0
void Func1()
{
}
extern boolean Func2();

the errors in line 7 are gone.

This does also work without stdlib.h and redefining the reserved macro NULL:

typedef int boolean;
#define FOO     bar
#define FOO     baz
void Func1()
{
}
extern boolean Func2();
commented
typedef int A; /* not finished yet... */
#error         /* preprocessor error during the semicolon consumption(!) casuses the previous declaration to fail */
extern A a;    /* A was not typedef'ed due to the previous failure */

Since cc65 currently does preprocessing during C declaration parsing, a preprocessor error would interfere with the error recovery of the parser. A separated preprocessor would be the future direction, but for now we may also implement "error categories" eg. tokenizer/syntax/constraint errors to fix/enhance error recovery.

This seems to have been working some time ago. 2.18 says:

test.c(3): Error: Macro redefinition is not identical

which is what I would expect. I think 2.18 also did preprocessing during C declaration parsing.

So while it's not a really serious error, it's definitely a regression which has cost me some time to debug. In my case, the dreamed up error was several hundred lines away from the macro redefinition and I knew it had worked with older compiler versions.

fixed via #2314