cppparser: Perform macro expansion on macro arguments

Fixes #1638
This commit is contained in:
rdb 2024-03-27 02:26:14 +01:00
parent 674c037c50
commit c923cf6ee5

View File

@ -2180,8 +2180,12 @@ expand_manifest(const CPPManifest *manifest, const YYLTYPE &loc) {
manifest->_variadic_param, args);
}
string expanded = " " + manifest->expand(args) + " ";
push_string(expanded, true);
// Perform expansion on the macro arguments.
for (string &arg : args) {
std::set<const CPPManifest *> expanded;
expanded.insert(manifest);
r_expand_manifests(arg, false, loc, expanded);
}
string expanded = " " + manifest->expand(args) + " ";
push_expansion(expanded, manifest, loc);
@ -2228,6 +2232,13 @@ r_expand_manifests(string &expr, bool expand_undefined,
manifest->_variadic_param, args, expr, p);
}
// Perform expansion on the macro arguments.
for (string &arg : args) {
std::set<const CPPManifest *> ignore = expanded;
ignore.insert(manifest);
r_expand_manifests(arg, expand_undefined, loc, ignore);
}
string result = manifest->expand(args);
// Recurse, but adding the manifest we just expanded to the list