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;
}
This commit is contained in:
Stephen Heumann 2022-05-24 22:38:56 -05:00
parent deca73d233
commit 58771ec71c
2 changed files with 4 additions and 2 deletions

View File

@ -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;

View File

@ -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.