Implement recursive macro expansion (for clang/gcc and cl with /Zc:preprocessor)
Does this only expand one level of macros?
That is, if I have two macros like
#define BAR(l,r) (l + r)
#define FOO(x) BAR(x,2)
and I write FOO(1) I would want this to say "Expands to (1 + 2)" since that is the final fully expanded form. Instead, it seems to say "Expands to BAR(1,2)" which is much less useful.
Or if showing the final form immediately isn't desirable maybe an way to trigger further expansion. Many macros are multiple levels in practice and the first expansion only doens't show much.
Originally posted by @travisdowns in https://github.com/Microsoft/vscode-cpptools/issues/1734#issuecomment-488921102
@travisdowns I'm not able to repro the issue. It fully expands for me. Can you give more repro details, such as your extension version, OS, compilerPath/intelliSenseMode, etc.?

C/C++ extension v0.22.1 vscode 1.33.1 Ubuntu 16.04
here's my c_cpp json:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": ["STRIDE=64", "_GNU_SOURCE"],
"compilerPath": "/usr/bin/gcc -march=haswell",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "${default}",
"browse": {
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
Okay, thanks for reporting this -- I repro it with WSL/gcc mode. Looks like there is an unexpected behavior difference in that case (seems like a bug).
The bug repros with VS 2019 -- I've reported the bug there: https://developercommunity.visualstudio.com/content/problem/556656/c-intellisense-macro-expansion-fails-to-fully-work.html . If you have a "Microsoft account" you could upvote that.
Hi, I work with WSL2/gcc and noticed that macros are not expanded recursively. Then I found this issue open since May 2019. Any chance to solve this issue in the nearest future?
The issue needs more upvotes on the developer community site.
Still suffering from this. Very hard to read source codes, specially linux kernel which relies on lots of nested macros :(
@lucaszanella I mentioned at https://developercommunity.visualstudio.com/content/problem/556656/c-intellisense-macro-expansion-fails-to-fully-work.html that the VS Code issue has more upvotes (versus the 2 on their page).
It turns out this is actually more of a feature request, because with the conformant preprocessor used by clang/gcc or cl with /Zc:preprocessor, the expanded macro info is not available to our parser, so fully expanding the macro is not trivial (as it is with cl without /Zc:preprocessor, which is not a standards compliant preprocessor implementation).
However, it has a lot of upvotes so maybe it'll meet the feature request bar eventually.
This would really be super helpful in a lot of cases as far as I am concerned. Because with more than 1 or 2 levels of nested macros, I end up being totally lost and cannot make any sense of the code I'm reading 😞 A perfect example of this is the C++ Google Test library, pretty impossible to decrypt without it.
To me that's the most important missing feature compared to other IDEs that have this implemented: Eclipse CDT with its macro expander, or CLion. Because otherwise I love VSCode and this extension!
This issue is a pretty bad paper cut in my everyday work. I started developing applications using the Zephyr RTOS, which heavily relies on macros for basically everything. Not being able to see the full expansion of those macros is making me consider switching to CLion for Zephyr development.
suffering from this in daily work. expecting this feature added to cpptools
very sorry to see this issue is still staying "Tracking" state since it was raised 3 years ago
@Shaka0723 Yeah, this is tied for 1st place for our features with the "Visual Studio" label (Tracking milestone), so I've pinged the team to let them know it's a higher priority feature for us. The linked VS bug appears as closed, but the internal issue is still open.
A fix is available with 1.14.1 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.14.1
爱你
Thanks for your great job!!!
Finally, after all these years!
Very cool!