@@ -5015,6 +5015,47 @@ static void tokenMacro15()
50155015 ASSERT_EQUALS (" D 1:1 use 1:3 unknown\n " , toString (macroUsage));
50165016}
50175017
5018+ static void tokenMacro16 ()
5019+ {
5020+ // a function-like macro name without ( is not expanded, so it is not a usage
5021+ const char code[] = " #define F(x) x\n "
5022+ " int F = F(1);\n " ;
5023+ std::list<simplecpp::MacroUsage> macroUsage;
5024+ ASSERT_EQUALS (" int(2:1) F(2:5) =(2:7) 1(2:9) ;(2:13)" , expandedTokens (code, simplecpp::DUI (), ¯oUsage));
5025+ ASSERT_EQUALS (" F 1:9 use 2:9\n " , toString (macroUsage));
5026+ }
5027+
5028+ static void tokenMacro17 ()
5029+ {
5030+ // a function-like macro name without ( in #if is a usage, also when the macro is defined before
5031+ std::list<simplecpp::MacroUsage> macroUsage;
5032+ preprocess (" #define F(x) 1\n #if F\n #endif\n " , ¯oUsage);
5033+ ASSERT_EQUALS (" F 1:9 use 2:5\n " , toString (macroUsage));
5034+ macroUsage.clear ();
5035+ preprocess (" #define F(x) 1\n #if 0\n #elif F || 1\n #endif\n " , ¯oUsage);
5036+ ASSERT_EQUALS (" F 1:9 use 3:7\n " , toString (macroUsage));
5037+ macroUsage.clear ();
5038+ preprocess (" #define F(x) 1\n #if F(0)\n #endif\n " , ¯oUsage);
5039+ ASSERT_EQUALS (" F 1:9 use 2:5\n " , toString (macroUsage));
5040+ }
5041+
5042+ static void tokenMacro18 ()
5043+ {
5044+ // a bare function-like macro name in an argument or a replacement list is not a usage
5045+ std::list<simplecpp::MacroUsage> macroUsage;
5046+ ASSERT_EQUALS (" \n\n F ;" , preprocess (" #define F(x) x\n #define G(a) a\n G(F);\n " , ¯oUsage));
5047+ ASSERT_EQUALS (" G 2:9 use 3:1\n " , toString (macroUsage));
5048+ macroUsage.clear ();
5049+ ASSERT_EQUALS (" \n\n F F 5 ;" , preprocess (" #define F(x) x\n #define H(a) a F a(5)\n H(F);\n " , ¯oUsage));
5050+ ASSERT_EQUALS (" F 1:9 use 3:1\n H 2:9 use 3:1\n " , toString (macroUsage));
5051+ macroUsage.clear ();
5052+ ASSERT_EQUALS (" \n 1" , preprocess (" #define F(x) x\n F\n (1)\n " , ¯oUsage));
5053+ ASSERT_EQUALS (" F 1:9 use 2:1\n " , toString (macroUsage));
5054+ macroUsage.clear ();
5055+ ASSERT_EQUALS (" \n F ; 1 ;" , preprocess (" #define F() 1\n F; F();\n " , ¯oUsage));
5056+ ASSERT_EQUALS (" F 1:9 use 2:4\n " , toString (macroUsage));
5057+ }
5058+
50185059/* * The argument of each macro usage as "name use line:col: [arg]", sorted. */
50195060static std::string argToString (const std::list<simplecpp::MacroUsage> ¯oUsage)
50205061{
@@ -5064,9 +5105,9 @@ static void macroUsageArg3()
50645105
50655106static void macroUsageArg4 ()
50665107{
5067- // object-like macro and function-like macro name without call have no argument
5108+ // object-like macro has no argument, function-like macro name without call is no usage
50685109 ASSERT_EQUALS (" INT64_C use 2:1: []\n " , macroUsageArg (" #define INT64_C 1\n INT64_C\n " ));
5069- ASSERT_EQUALS (" INT64_C use 2:1: [] \n " , macroUsageArg (" #define INT64_C(x) x\n INT64_C;\n " ));
5110+ ASSERT_EQUALS (" " , macroUsageArg (" #define INT64_C(x) x\n INT64_C;\n " ));
50705111}
50715112
50725113static void macroUsageArg5 ()
@@ -6243,6 +6284,9 @@ static void runTests(int argc, char **argv, Input input)
62436284 TEST_CASE (tokenMacro13);
62446285 TEST_CASE (tokenMacro14);
62456286 TEST_CASE (tokenMacro15);
6287+ TEST_CASE (tokenMacro16);
6288+ TEST_CASE (tokenMacro17);
6289+ TEST_CASE (tokenMacro18);
62466290 TEST_CASE (macroUsageArg1);
62476291 TEST_CASE (macroUsageArg2);
62486292 TEST_CASE (macroUsageArg3);
0 commit comments