Skip to content

Commit 5435607

Browse files
committed
Test usages of bare function-like macro names in arguments
tokenMacro18 covers the cases the change affects beyond a bare name at the top level: G(F) and a replacement list that names F without ( record no usage of F, while F followed by ( on the next line, and F() after a bare F, each record one.
1 parent 65dfba6 commit 5435607

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎test.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,6 +5000,23 @@ static void tokenMacro17()
50005000
ASSERT_EQUALS("F 1:9 use 2:5\n", toString(macroUsage));
50015001
}
50025002

5003+
static void tokenMacro18()
5004+
{
5005+
// a bare function-like macro name in an argument or a replacement list is not a usage
5006+
std::list<simplecpp::MacroUsage> macroUsage;
5007+
ASSERT_EQUALS("\n\nF ;", preprocess("#define F(x) x\n#define G(a) a\nG(F);\n", &macroUsage));
5008+
ASSERT_EQUALS("G 2:9 use 3:1\n", toString(macroUsage));
5009+
macroUsage.clear();
5010+
ASSERT_EQUALS("\n\nF F 5 ;", preprocess("#define F(x) x\n#define H(a) a F a(5)\nH(F);\n", &macroUsage));
5011+
ASSERT_EQUALS("F 1:9 use 3:1\nH 2:9 use 3:1\n", toString(macroUsage));
5012+
macroUsage.clear();
5013+
ASSERT_EQUALS("\n1", preprocess("#define F(x) x\nF\n(1)\n", &macroUsage));
5014+
ASSERT_EQUALS("F 1:9 use 2:1\n", toString(macroUsage));
5015+
macroUsage.clear();
5016+
ASSERT_EQUALS("\nF ; 1 ;", preprocess("#define F() 1\nF; F();\n", &macroUsage));
5017+
ASSERT_EQUALS("F 1:9 use 2:4\n", toString(macroUsage));
5018+
}
5019+
50035020
/** The argument of each macro usage as "name use line:col: [arg]", sorted. */
50045021
static std::string argToString(const std::list<simplecpp::MacroUsage> &macroUsage)
50055022
{
@@ -6172,6 +6189,7 @@ static void runTests(int argc, char **argv, Input input)
61726189
TEST_CASE(tokenMacro15);
61736190
TEST_CASE(tokenMacro16);
61746191
TEST_CASE(tokenMacro17);
6192+
TEST_CASE(tokenMacro18);
61756193
TEST_CASE(macroUsageArg1);
61766194
TEST_CASE(macroUsageArg2);
61776195
TEST_CASE(macroUsageArg3);

0 commit comments

Comments
 (0)