Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,12 @@ namespace simplecpp {
std::cout << " expand " << name() << " " << locstring(defineLocation()) << std::endl;
#endif

// No arguments => not macro expansion
if (functionLike() && nameTokInst->next && nameTokInst->next->op != '(') {
output.push_back(new Token(nameTokInst->str(), loc));
return nameTokInst->next;
}

usageList.emplace_back(loc);

if (expandBuiltin(output, loc, nameTokInst))
Expand All @@ -2363,12 +2369,6 @@ namespace simplecpp {
const bool calledInDefine = (loc.fileIndex != nameTokInst->location.fileIndex ||
loc.line < nameTokInst->location.line);

// No arguments => not macro expansion
if (functionLike() && nameTokInst->next && nameTokInst->next->op != '(') {
output.push_back(new Token(nameTokInst->str(), loc));
return nameTokInst->next;
}

std::vector<const Token*> parametertokens1(getMacroParameters(nameTokInst, calledInDefine));

// If macro call uses __COUNTER__ then expand that first
Expand Down
11 changes: 11 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4788,6 +4788,16 @@ static void tokenMacro15()
ASSERT_EQUALS("D 1:1 use 1:3 unknown\n", toString(macroUsage));
}

static void tokenMacro16()
{
// a function-like macro name without ( is not expanded, so it is not a usage
const char code[] = "#define F(x) x\n"
"int F = F(1);\n";
std::list<simplecpp::MacroUsage> macroUsage;
ASSERT_EQUALS("int(2:1) F(2:5) =(2:7) 1(2:9) ;(2:13)", expandedTokens(code, simplecpp::DUI(), &macroUsage));
ASSERT_EQUALS("F 1:9 use 2:9\n", toString(macroUsage));
}

static void undef()
{
const char code[] = "#define A\n"
Expand Down Expand Up @@ -5864,6 +5874,7 @@ static void runTests(int argc, char **argv, Input input)
TEST_CASE(tokenMacro13);
TEST_CASE(tokenMacro14);
TEST_CASE(tokenMacro15);
TEST_CASE(tokenMacro16);

TEST_CASE(undef);

Expand Down
Loading