fix: Paste tokens in arguments of nested macros (#1062)

This commit is contained in:
wroy authored and GitHub committed 2026-10-31 09:54:46 +01:00
1 parent c266c160a8
commit 4271677e15
2 files changed
+39 -1

No files matched your search

+19 -1
View File
@@ -7,6 +7,7 @@
#include "Parsing/Simple/SimpleExpressionInterpreter.h"
#include "Utils/StringUtils.h"
#include <algorithm>
#include <regex>
#include <sstream>
#include <utility>
@@ -879,8 +880,25 @@ void DefinesStreamProxy::ExpandMacro(ParserLine& line,
const Define* macro,
const std::vector<std::string>& parameterValues)
{
std::vector<std::string> pastedValues;
const auto* values = &parameterValues;
if (std::ranges::any_of(parameterValues,
[](const std::string& value)
{
return value.find("##") != std::string::npos;
}))
{
pastedValues = parameterValues;
for (auto& value : pastedValues)
{
if (value.find("##") != std::string::npos)
ProcessTokenPastingOperators(line, linePos, value);
}
values = &pastedValues;
}
std::ostringstream rawOutput;
InsertMacroParameters(rawOutput, macro, parameterValues);
InsertMacroParameters(rawOutput, macro, *values);
std::string str = rawOutput.str();
ProcessNestedMacros(line, linePos, callstack, str);
@@ -1127,6 +1127,26 @@ namespace test::parsing::impl::defines_stream_proxy
REQUIRE(proxy.Eof());
}
TEST_CASE("DefinesStreamProxy: Can use token-pasting operator in arguments of nested macros", "[parsing][parsingstream]")
{
const std::vector<std::string> lines{
"#define s(t) #t",
"#define tag(id) s(id##_tag)",
"#define outer(list) tag(list##_member0)",
"outer(party)",
};
MockParserLineStream mockStream(lines);
DefinesStreamProxy proxy(&mockStream);
ExpectLine(&proxy, 1, "");
ExpectLine(&proxy, 2, "");
ExpectLine(&proxy, 3, "");
ExpectLine(&proxy, 4, "\"party_member0_tag\"");
REQUIRE(proxy.Eof());
}
TEST_CASE("DefinesStreamProxy: Can use token-pasting operator with string and stringization outside macro", "[parsing][parsingstream]")
{
const std::vector<std::string> lines{