vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Implement recursive macro expansion (for clang/gcc and cl with /Zc:preprocessor)

Open sean-mcmanus opened this issue 7 years ago • 19 comments

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

sean-mcmanus avatar May 03 '19 19:05 sean-mcmanus

@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.?

image

sean-mcmanus avatar May 03 '19 19:05 sean-mcmanus

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
}

travisdowns avatar May 03 '19 19:05 travisdowns

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).

sean-mcmanus avatar May 03 '19 19:05 sean-mcmanus

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.

sean-mcmanus avatar May 03 '19 20:05 sean-mcmanus

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?

eruanno123 avatar Oct 07 '20 08:10 eruanno123

The issue needs more upvotes on the developer community site.

sean-mcmanus avatar Oct 08 '20 17:10 sean-mcmanus

Still suffering from this. Very hard to read source codes, specially linux kernel which relies on lots of nested macros :(

lattice0 avatar Nov 20 '20 06:11 lattice0

@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).

sean-mcmanus avatar Nov 20 '20 06:11 sean-mcmanus

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.

sean-mcmanus avatar Jul 03 '21 02:07 sean-mcmanus

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!

Skyline124 avatar Aug 31 '21 02:08 Skyline124

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.

andresovela avatar Oct 07 '22 22:10 andresovela

suffering from this in daily work. expecting this feature added to cpptools

Shaka0723 avatar Dec 14 '22 06:12 Shaka0723

very sorry to see this issue is still staying "Tracking" state since it was raised 3 years ago

Shaka0723 avatar Dec 15 '22 06:12 Shaka0723

@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.

sean-mcmanus avatar Dec 15 '22 22:12 sean-mcmanus

A fix is available with 1.14.1 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.14.1

sean-mcmanus avatar Feb 03 '23 02:02 sean-mcmanus

爱你

heartacker avatar Feb 03 '23 03:02 heartacker

Thanks for your great job!!!

Shaka0723 avatar Feb 03 '23 08:02 Shaka0723

Finally, after all these years!

meijialun avatar Feb 08 '23 05:02 meijialun

Very cool!

dev-joss avatar Feb 14 '23 19:02 dev-joss