Skip to content

Commit 26ceaf9

Browse files
committed
Add more test cases
1 parent 148b1c2 commit 26ceaf9

1 file changed

Lines changed: 43 additions & 10 deletions

File tree

‎test.cpp‎

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -993,16 +993,49 @@ static void define27()
993993
{
994994
// an expansion result inside a macro argument that is a function-like macro
995995
// name must be rescanned against the remaining argument tokens
996-
const char code[] = "#define o1(a) a()\n"
997-
"#define b(c, d) c##d\n"
998-
"#define l(c, d) b(c, 1)\n"
999-
"#define m(e, f)\n"
1000-
"#define g(h, i) m(h, )\n"
1001-
"#define j(h, i) g(h, )\n"
1002-
"#define k() l(j(, ), )\n"
1003-
"#define n(a) j(l(o, )(a), )\n"
1004-
"n(k)\n";
1005-
ASSERT_EQUALS("", preprocess(code));
996+
const char code1[] = "#define f(x) [x]\n"
997+
"#define ID(x) x\n"
998+
"#define G() f\n"
999+
"ID(G()(1))\n";
1000+
ASSERT_EQUALS("\n"
1001+
"\n"
1002+
"\n"
1003+
"[ 1 ]", preprocess(code1));
1004+
1005+
// the rescanned call's arguments are themselves rescanned
1006+
const char code2[] = "#define f(x) [x]\n"
1007+
"#define ID(x) x\n"
1008+
"#define G() f\n"
1009+
"ID(G()(G()(2)))\n";
1010+
ASSERT_EQUALS("\n"
1011+
"\n"
1012+
"\n"
1013+
"[ [ 2 ] ]", preprocess(code2));
1014+
1015+
// each rescan round must use the right set of already-expanded macros:
1016+
// A(1)->B, B(2)->A, A(3)->B, B(4)->A
1017+
const char code3[] = "#define ID(x) x\n"
1018+
"#define A(x) B\n"
1019+
"#define B(x) A\n"
1020+
"ID(A(1)(2)(3)(4))\n";
1021+
ASSERT_EQUALS("\n"
1022+
"\n"
1023+
"\n"
1024+
"A", preprocess(code3));
1025+
1026+
// creduce'd fuzzer case: the missed rescan of o1(k) deferred the call to a
1027+
// context where j was wrongly blocked from expanding, so b pasted ')' and
1028+
// '1' into an invalid token that broke the parentheses of the m call
1029+
const char code4[] = "#define o1(a) a()\n"
1030+
"#define b(c, d) c##d\n"
1031+
"#define l(c, d) b(c, 1)\n"
1032+
"#define m(e, f)\n"
1033+
"#define g(h, i) m(h, )\n"
1034+
"#define j(h, i) g(h, )\n"
1035+
"#define k() l(j(, ), )\n"
1036+
"#define n(a) j(l(o, )(a), )\n"
1037+
"n(k)\n";
1038+
ASSERT_EQUALS("", preprocess(code4));
10061039
}
10071040

10081041

0 commit comments

Comments
 (0)