From fd7f32ecd3c3bcb331612a17b79e25a8f1ee8b99 Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 22 Aug 2022 14:31:51 +0800 Subject: [PATCH 1/2] Improved error handling and diagnostics with failed macro definitions. --- src/cc65/preproc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index f1328c4d0..ffae5baa6 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -1004,6 +1004,7 @@ static void DoDefine (void) if (CurC != '.' || NextC != '.') { PPError ("'...' expected"); ClearLine (); + FreeMacro (M); return; } NextChar (); @@ -1043,8 +1044,9 @@ static void DoDefine (void) /* Check for a right paren and eat it if we find one */ if (CurC != ')') { - PPError ("')' expected"); + PPError ("')' expected for macro definition"); ClearLine (); + FreeMacro (M); return; } NextChar (); From 57ad7c87661f2bf313321e71476f5b75ecaaf548 Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 22 Aug 2022 14:31:53 +0800 Subject: [PATCH 2/2] Improved diagnostics about C++ style comments for c89. --- src/cc65/preproc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index ffae5baa6..a49fade20 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -400,6 +400,11 @@ static void OldStyleComment (void) static void NewStyleComment (void) /* Remove a new style C comment from line. */ { + /* Diagnose if this is unsupported */ + if (IS_Get (&Standard) < STD_C99) { + PPError ("C++ style comments are not allowed in C89"); + } + /* Beware: Because line continuation chars are handled when reading ** lines, we may only skip until the end of the source line, which ** may not be the same as the end of the input line. The end of the @@ -432,7 +437,7 @@ static int SkipWhitespace (int SkipLines) } else if (CurC == '/' && NextC == '*') { OldStyleComment (); Skipped = 1; - } else if (IS_Get (&Standard) >= STD_C99 && CurC == '/' && NextC == '/') { + } else if (CurC == '/' && NextC == '/') { NewStyleComment (); Skipped = 1; } else if (CurC == '\0' && SkipLines) { @@ -1560,7 +1565,7 @@ static void TranslationPhase3 (StrBuf* Source, StrBuf* Target) } else if (CurC == '/' && NextC == '*') { OldStyleComment (); HasWhiteSpace = 1; - } else if (IS_Get (&Standard) >= STD_C99 && CurC == '/' && NextC == '/') { + } else if (CurC == '/' && NextC == '/') { NewStyleComment (); HasWhiteSpace = 1; } else {