@@ -1161,6 +1161,42 @@ static void define_invalid_3()
11611161 TODO_ASSERT_EQUALS (" " , " file0,2,syntax_error,failed to expand 'R', Wrong number of parameters for macro 'R'.\n " , toString (outputList));
11621162}
11631163
1164+ static void define_wrong_number_of_arguments ()
1165+ {
1166+ {
1167+ simplecpp::OutputList outputList;
1168+ ASSERT_EQUALS (" " , preprocess (" #define f(a,b) a+b\n f(1)\n " , &outputList));
1169+ ASSERT_EQUALS (" file0,2,syntax_error,failed to expand 'f', Wrong number of parameters for macro 'f'.\n " , toString (outputList));
1170+ }
1171+ {
1172+ simplecpp::OutputList outputList;
1173+ ASSERT_EQUALS (" " , preprocess (" #define f(a,b) a+b\n f(1,2,3)\n " , &outputList));
1174+ ASSERT_EQUALS (" file0,2,syntax_error,failed to expand 'f', Wrong number of parameters for macro 'f'.\n " , toString (outputList));
1175+ }
1176+ {
1177+ simplecpp::OutputList outputList;
1178+ ASSERT_EQUALS (" " , preprocess (" #define f(a,b,...) a+b\n f(1)\n " , &outputList));
1179+ ASSERT_EQUALS (" file0,2,syntax_error,failed to expand 'f', Wrong number of parameters for macro 'f'.\n " , toString (outputList));
1180+ }
1181+ {
1182+ simplecpp::OutputList outputList;
1183+ ASSERT_EQUALS (" \n 1" , preprocess (" #define f(a,...) a __VA_ARGS__\n f(1)\n " , &outputList));
1184+ ASSERT_EQUALS (" " , toString (outputList));
1185+ }
1186+ {
1187+ // a function-like macro name that is not followed by ( is not expanded
1188+ simplecpp::OutputList outputList;
1189+ ASSERT_EQUALS (" \n f ;" , preprocess (" #define f(a) a\n f;\n " , &outputList));
1190+ ASSERT_EQUALS (" " , toString (outputList));
1191+ }
1192+ {
1193+ // TODO: f takes no arguments, gcc reports an error
1194+ simplecpp::OutputList outputList;
1195+ TODO_ASSERT_EQUALS (" " , " \n 1" , preprocess (" #define f() 1\n f(1)\n " , &outputList));
1196+ TODO_ASSERT_EQUALS (" file0,2,syntax_error,failed to expand 'f', Wrong number of parameters for macro 'f'.\n " , " " , toString (outputList));
1197+ }
1198+ }
1199+
11641200static void define_invalid_4 ()
11651201{
11661202 const char code[] = " #define X(...)\n "
@@ -5546,6 +5582,7 @@ static void runTests(int argc, char **argv, Input input)
55465582 TEST_CASE (define_invalid_2);
55475583 TEST_CASE (define_invalid_3);
55485584 TEST_CASE (define_invalid_4);
5585+ TEST_CASE (define_wrong_number_of_arguments);
55495586 TEST_CASE (define_define_1);
55505587 TEST_CASE (define_define_2);
55515588 TEST_CASE (define_define_3);
0 commit comments