From 58771ec71c63a4501d5bfe8d3ec4273e24b71326 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 24 May 2022 22:38:56 -0500 Subject: [PATCH] Do not do macro expansion after each ## operator is evaluated. It should only be done after all the ## operators in the macro have been evaluated, potentially merging together several tokens via successive ## operators. Here is an example illustrating the problem: #define merge(a,b,c) a##b##c #define foobar #define foobarbaz a int merge(foo,bar,baz) = 42; int main(void) { return a; } --- Scanner.pas | 4 ++-- cc.notes | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Scanner.pas b/Scanner.pas index d483c7b..c0052b4 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -1265,9 +1265,9 @@ if class1 in [identifier,reservedWord] then begin token.kind := ident; token.class := identifier; token.numString := nil; - token.name := @workString; token.symbolPtr := nil; - CheckIdentifier; + token.name := pointer(Malloc(length(workString)+1)); + CopyString(pointer(token.name), @workString); tk1 := token; token := lt; goto 1; diff --git a/cc.notes b/cc.notes index 8a0df2f..82ed6a2 100644 --- a/cc.notes +++ b/cc.notes @@ -1805,6 +1805,8 @@ int foo(int[42]); 184. If a macro was declared with the same name as a keyword or a typedef, and that name was also used within another macro, the first macro would not be correctly expanded within invocations of the second macro. (This is a bug that was previously fixed in ORCA/C 2.1.1 B3, but was subsequently reintroduced.) +185. In the invocation of a macro with multiple ## operators, each successive token formed by a ## operator could be subject to macro replacement (if there was a macro of that name). Macro replacement should instead only be done after all ## operators have been evaluated. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.