From 5cef3c133f95f8e5bf793420ea4236734a9af8a4 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 14:19:04 +0200 Subject: [PATCH 01/10] test.cpp: added test for #296 --- test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test.cpp b/test.cpp index bc8cb4d5..e43dc87f 100644 --- a/test.cpp +++ b/test.cpp @@ -691,6 +691,18 @@ static void define13() "}", preprocess(code)); } +static void define14() // #296 +{ + const char code[] = "#define bar(x) x % 2\n" + "#define foo(x) printf(#x \"\\n\")\n" + "\n" + " foo(bar(3));\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "printf ( \"bar(3)\" \"\\n\" ) ;", preprocess(code)); +} + static void define_invalid_1() @@ -3655,6 +3667,7 @@ int main(int argc, char **argv) TEST_CASE(define11); TEST_CASE(define12); TEST_CASE(define13); + TEST_CASE(define14); // #296 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From 9ef5900e1e6c34fc391eb8f4839e8649a1935d14 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 14:22:00 +0200 Subject: [PATCH 02/10] test.cpp: added test for #231 --- test.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test.cpp b/test.cpp index e43dc87f..4be9e2b2 100644 --- a/test.cpp +++ b/test.cpp @@ -703,6 +703,23 @@ static void define14() // #296 "printf ( \"bar(3)\" \"\\n\" ) ;", preprocess(code)); } +static void define15() // #231 +{ + const char code[] = "#define CAT(a, b) CAT2(a, b)\n" + "#define CAT2(a, b) a ## b\n" + "#define FOO x\n" + "#define BAR() CAT(F, OO)\n" + "#define BAZ CAT(B, AR)()\n" + "BAZ\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "\n" + "\n" + "x", preprocess(code)); +} + + static void define_invalid_1() @@ -3668,6 +3685,7 @@ int main(int argc, char **argv) TEST_CASE(define12); TEST_CASE(define13); TEST_CASE(define14); // #296 + TEST_CASE(define15); // #231 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From a03d86474b9c5c783a771f4149c3865ed1cb9f51 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 14:24:16 +0200 Subject: [PATCH 03/10] test.cpp: added test for #217 --- test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test.cpp b/test.cpp index 4be9e2b2..fc0d3959 100644 --- a/test.cpp +++ b/test.cpp @@ -1182,6 +1182,15 @@ static void pragma_backslash() ASSERT_EQUALS("", preprocess(code, &outputList)); } +static void pragma_backslash_2() // #217 +{ + const char code[] = "#pragma comment(linker, \"foo \\\n" + "bar\")\n"; + + simplecpp::OutputList outputList; + ASSERT_EQUALS("", preprocess(code, &outputList)); +} + static void dollar() { ASSERT_EQUALS("$ab", readfile("$ab")); @@ -3728,6 +3737,7 @@ int main(int argc, char **argv) TEST_CASE(define_va_opt_9); // #632 TEST_CASE(pragma_backslash); // multiline pragma directive + TEST_CASE(pragma_backslash_2); // #217 // UB: #ifdef as macro parameter TEST_CASE(define_ifdef); From 51e12d46aa3caa3730429c6076fce529fb245fb1 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 14:28:48 +0200 Subject: [PATCH 04/10] test.cpp: added test for #201 --- test.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test.cpp b/test.cpp index fc0d3959..31318e59 100644 --- a/test.cpp +++ b/test.cpp @@ -719,6 +719,41 @@ static void define15() // #231 "x", preprocess(code)); } +static void define16() // #201 +{ + const char code[] = "#define ALL_COLORS(warm_colors) \\\n" + " X(Blue) \\\n" + " X(Green) \\\n" + " X(Purple) \\\n" + " warm_colors\n" + "\n" + "#define WARM_COLORS \\\n" + " X(Red) \\\n" + " X(Yellow) \\\n" + " X(Orange)\n" + "\n" + "#define COLOR_SET ALL_COLORS(WARM_COLORS)\n" + "\n" + "#define X(color) #color,\n" + "\n" + "COLOR_SET\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\"Blue\" , \"Green\" , \"Purple\" , \"Red\" , \"Yellow\" , \"Orange\" ,", preprocess(code)); +} @@ -3695,6 +3730,7 @@ int main(int argc, char **argv) TEST_CASE(define13); TEST_CASE(define14); // #296 TEST_CASE(define15); // #231 + TEST_CASE(define16); // #201 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From 1d718fc58652c2a22b3ed86fc3e042a0daf70678 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 18:17:56 +0200 Subject: [PATCH 05/10] test.cpp: added test for #185 --- test.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test.cpp b/test.cpp index 31318e59..6f2b684c 100644 --- a/test.cpp +++ b/test.cpp @@ -755,6 +755,33 @@ static void define16() // #201 "\"Blue\" , \"Green\" , \"Purple\" , \"Red\" , \"Yellow\" , \"Orange\" ,", preprocess(code)); } +static void define17() // #185 +{ + const char code[] = "#define at(x, y) x##y\n" + "#define b(...) \\\n" + "aa(__VA_ARGS__, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , \\\n" + ", , , , , , , , 2)\n" + "#define aa(c, d, a, b, e, f, g, h, ab, ac, i, ad, j, k, l, m, n, o, p, ae, q, \\\n" + "r, s, t, u, v, w, x, y, z, af, ag, ah, ai, aj, ak, al, am, an, ao, \\\n" + "ap) \\\n" + "ap\n" + "#define aq(...) ar(b(__VA_ARGS__), __VA_ARGS__) static_assert(true, \" \")\n" + "#define ar(ap, ...) at(I_, ap)(__VA_ARGS__)\n" + "#define I_2(as, a)\n" + "aq(a, array);\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "static_assert ( true , \" \" ) ;", preprocess(code)); +} static void define_invalid_1() @@ -3731,6 +3758,7 @@ int main(int argc, char **argv) TEST_CASE(define14); // #296 TEST_CASE(define15); // #231 TEST_CASE(define16); // #201 + TEST_CASE(define17); // #185 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From f79cb6c7f5f7a3d8faee05f2ee378ae02593173a Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 18:21:46 +0200 Subject: [PATCH 06/10] test.cpp: added test for #130 --- test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test.cpp b/test.cpp index 6f2b684c..2d575d92 100644 --- a/test.cpp +++ b/test.cpp @@ -783,6 +783,18 @@ static void define17() // #185 "static_assert ( true , \" \" ) ;", preprocess(code)); } +static void define18() // #130 +{ + const char code[] = "#define MAC2STR(x) x[0],x[1],x[2],x[3],x[4],x[5]\n" + "#define FT_DEBUG(fmt, args...) if(pGlobalCtx && pGlobalCtx->debug_level>=2) printf(\"FT-dbg: \"fmt, ##args)\n" + "\n" + "FT_DEBUG(\" %02x:%02x:%02x:%02x:%02x:%02x\\n\", MAC2STR(pCtx->wlan_intf_addr[i]));\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "if ( pGlobalCtx && pGlobalCtx -> debug_level >= 2 ) printf ( \"FT-dbg: \" \" %02x:%02x:%02x:%02x:%02x:%02x\\n\" , pCtx -> wlan_intf_addr [ i ] [ 0 ] , pCtx -> wlan_intf_addr [ i ] [ 1 ] , pCtx -> wlan_intf_addr [ i ] [ 2 ] , pCtx -> wlan_intf_addr [ i ] [ 3 ] , pCtx -> wlan_intf_addr [ i ] [ 4 ] , pCtx -> wlan_intf_addr [ i ] [ 5 ] ) ;", preprocess(code)); +} + static void define_invalid_1() { @@ -3759,6 +3771,7 @@ int main(int argc, char **argv) TEST_CASE(define15); // #231 TEST_CASE(define16); // #201 TEST_CASE(define17); // #185 + TEST_CASE(define18); // #130 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From 214bc607c2aa036f01e09c7f175f54c76e641436 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 18:23:41 +0200 Subject: [PATCH 07/10] test.cpp: added test for #124 --- test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test.cpp b/test.cpp index 2d575d92..a44e9f7f 100644 --- a/test.cpp +++ b/test.cpp @@ -795,6 +795,18 @@ static void define18() // #130 "if ( pGlobalCtx && pGlobalCtx -> debug_level >= 2 ) printf ( \"FT-dbg: \" \" %02x:%02x:%02x:%02x:%02x:%02x\\n\" , pCtx -> wlan_intf_addr [ i ] [ 0 ] , pCtx -> wlan_intf_addr [ i ] [ 1 ] , pCtx -> wlan_intf_addr [ i ] [ 2 ] , pCtx -> wlan_intf_addr [ i ] [ 3 ] , pCtx -> wlan_intf_addr [ i ] [ 4 ] , pCtx -> wlan_intf_addr [ i ] [ 5 ] ) ;", preprocess(code)); } +static void define19() // #124 +{ + const char code[] = "#define CONCAT(tok) tok##suffix\n" + "\n" + "CONCAT(Test);\n" + "CONCAT(const Test);\n"; + ASSERT_EQUALS("\n" + "\n" + "Testsuffix ;\n" + "const Testsuffix ;", preprocess(code)); +} + static void define_invalid_1() { @@ -3772,6 +3784,7 @@ int main(int argc, char **argv) TEST_CASE(define16); // #201 TEST_CASE(define17); // #185 TEST_CASE(define18); // #130 + TEST_CASE(define19); // #124 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From 6f777654acb86444945f0ae187ee40ab370e12c5 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 18:25:49 +0200 Subject: [PATCH 08/10] test.cpp: added test for #113 --- test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test.cpp b/test.cpp index a44e9f7f..81b7b07e 100644 --- a/test.cpp +++ b/test.cpp @@ -807,6 +807,18 @@ static void define19() // #124 "const Testsuffix ;", preprocess(code)); } +static void define20() // #113 +{ + const char code[] = "#define TARGS4 T1,T2,T3,T4\n" + "#define FOOIMPL(T__CLASS, TARGS) void foo(const T__CLASS& x) { }\n" + "#define FOOIMPL_4(T__CLASS) FOOIMPL(T__CLASS, TARGS4)\n" + "FOOIMPL_4(y)\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "void foo ( const y < T1 , T2 , T3 , T4 > & x ) { }", preprocess(code)); +} + static void define_invalid_1() { @@ -3785,6 +3797,7 @@ int main(int argc, char **argv) TEST_CASE(define17); // #185 TEST_CASE(define18); // #130 TEST_CASE(define19); // #124 + TEST_CASE(define20); // #113 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From d70570cf855755516b1fad04ba11572c34220e9d Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 18:27:34 +0200 Subject: [PATCH 09/10] test.cpp: added test for #66 --- test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test.cpp b/test.cpp index 81b7b07e..0e7221aa 100644 --- a/test.cpp +++ b/test.cpp @@ -819,6 +819,16 @@ static void define20() // #113 "void foo ( const y < T1 , T2 , T3 , T4 > & x ) { }", preprocess(code)); } +static void define21() // #66 +{ + const char code[] = "#define GETMYID(a) ((a))+1\n" + "#define FIGHT_FOO(c, ...) foo(c, ##__VA_ARGS__)\n" + "FIGHT_FOO(1, GETMYID(a));\n"; + ASSERT_EQUALS("\n" + "\n" + "foo ( 1 , ( ( a ) ) + 1 ) ;", preprocess(code)); +} + static void define_invalid_1() { @@ -3798,6 +3808,7 @@ int main(int argc, char **argv) TEST_CASE(define18); // #130 TEST_CASE(define19); // #124 TEST_CASE(define20); // #113 + TEST_CASE(define21); // #66 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1); From c531b0f9d74a1daaa62d9679adc94337bb43033e Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 13 Apr 2026 18:33:24 +0200 Subject: [PATCH 10/10] test.cpp: added tests for #40 --- test.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test.cpp b/test.cpp index 0e7221aa..4242f68b 100644 --- a/test.cpp +++ b/test.cpp @@ -829,6 +829,44 @@ static void define21() // #66 "foo ( 1 , ( ( a ) ) + 1 ) ;", preprocess(code)); } +static void define22() // #40 +{ + const char code[] = "#define COUNTER_NAME(NAME, ...) NAME##Count\n" + "#define COMMA ,\n" + "\n" + "#define DECLARE_COUNTERS(LIST) unsigned long LIST(COUNTER_NAME, COMMA);\n" + "\n" + "#define ACTUAL_LIST(FUNCTION, SEPARATOR) \\\n" + "FUNCTION(event1, int, foo) SEPARATOR \\\n" + "FUNCTION(event2, char, bar)\n" + "\n" + "DECLARE_COUNTERS(ACTUAL_LIST)\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "unsigned long event1Count , event2Count ;", preprocess(code)); +} + +static void define23() // #40 +{ + const char code[] = "#define COMMA ,\n" + "#define MULTI(SEPARATOR) A SEPARATOR B\n" + "\n" + "#define VARS MULTI(COMMA)\n" + "unsigned VARS;\n"; + ASSERT_EQUALS("\n" + "\n" + "\n" + "\n" + "unsigned A , B ;", preprocess(code)); +} + static void define_invalid_1() { @@ -3809,6 +3847,8 @@ int main(int argc, char **argv) TEST_CASE(define19); // #124 TEST_CASE(define20); // #113 TEST_CASE(define21); // #66 + TEST_CASE(define22); // #40 + TEST_CASE(define23); // #40 TEST_CASE(define_invalid_1); TEST_CASE(define_invalid_2); TEST_CASE(define_define_1);