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

Variadic macro not expanded correctly

Open stephane-archer opened this issue 3 years ago • 4 comments

In the following code:

#define Get2ndVariadicArg(a, b, ...) b

#define Assert(condition, ...) HandleAssert("msg", Get2ndVariadicArg(0, ##__VA_ARGS__, #condition))

#define HandleAssert(msg, format) MyAssert(msg, format)

int main()
{
    void * p = nullptr;
    auto mytest = Assert(p != nullptr);
}

visual studio code IntelliSense expend the Assert macro like this:

auto mytest = MyAssert("msg", )

but cl /P /C main.cpp expend the macro the following

auto mytest = MyAssert("msg", "p != nullptr");

How can I have a consistent behavior with cl? Is it a bug in IntelliSense?

stephane-archer avatar Sep 21 '21 15:09 stephane-archer

Hi @stephane-archer . Thanks for reporting this. I'm able to repro. The issue also repro's in VS, which shares the same IntelliSense implementation. I've opened an issue internally against VS to address this.

Colengms avatar Sep 22 '21 20:09 Colengms

I take it that this is the same issue I'm seeing here? image

Ma-XX-oN avatar Oct 29 '21 15:10 Ma-XX-oN

@Ma-XX-oN I believe so.

sean-mcmanus avatar Nov 02 '21 01:11 sean-mcmanus

This is tracked internally as 1409182, but there are multiple other VA_ARGS/macro issues that may be duplicates as well.

sean-mcmanus avatar Apr 11 '22 22:04 sean-mcmanus

@stephane-archer @Ma-XX-oN Fixed in 1.13.1: https://github.com/microsoft/vscode-cpptools/releases/tag/v1.13.1

sean-mcmanus avatar Sep 28 '22 06:09 sean-mcmanus

@sean-mcmanus you are the best! :D

stephane-archer avatar Sep 28 '22 11:09 stephane-archer

Glad to hear that this got fixed. Well done!

Adrian-Hawryluk avatar Oct 03 '22 12:10 Adrian-Hawryluk