microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

errorSquiggles 'user-defined literal operator not found' for macro #1069

Open startup73 opened 7 years ago

startup73 commented 7 years ago

Operating Sytem:Win7 X86_64 VS Code: V1.17.0-insider C/C++ extension version: 0.13.0

only if

a.h

#define LOG_ERROR(format, argv...) do {    \
                printf("[%s|%d]"format, __FILE__, __LINE__, ##argv); \
} while (0)

a.cpp

#include "a.h"
...
LOG_ERROR("%s", "abc");
...
bobbrow commented 7 years ago

Thanks for reporting this. I also saw it last week while getting a demo ready for CppCon, but forgot to log an issue for it. I was able to work around the issue by adding whitespace between the quoted text and the argument (e.g. "format" in your case)

katjie commented 5 years ago

I have noticed this as well, still now. When I use catch2 (c++ testing framework), all of my REQUIRE macros will be underlined with this "error".

sean-mcmanus commented 5 years ago

The bug repros with Visual Studio as well. I've reported bug https://developercommunity.visualstudio.com/content/problem/377739/c-intellisense-reports-invalid-user-defined-litera.html .

As a workaround, you could use "[%s|%d]"##format or "[%s|%d]" format as Bob suggested.

You also need a comma before the "...".

pedzed commented 5 years ago

When I use catch2 (c++ testing framework), all of my REQUIRE macros will be underlined with this "error".

I am using Catch2 as well and it is driving me crazy. What have you done in the mean time? Disable error squiggles altogether?

image

katjie commented 5 years ago

Hi @pedzed
I reported issue #2786 which relates a little bit more to my specific case with Catch2. Maybe you can try some of the suggestions made in there, however I found them unsuccessful. However, for unrelated reasons, we have since decided to use GoogleTest instead. GoogleTest did not have this problem.

colinaaa commented 5 years ago

I'm using Catch2, and I'm getting the same problem!

shehabattia96 commented 4 years ago

Upvote, it's driving me insane too. Using Catch2!

sean-mcmanus commented 4 years ago

@shehabattia96 Upvotes to this issue may not be "counted", because the issue is being tracked by https://developercommunity.visualstudio.com/content/problem/377739/c-intellisense-reports-invalid-user-defined-litera.html , but that requies a Microsoft account to upvote.

I've filed a request to enable GitHub users to upvote VS issues without a Microsoft account at https://developercommunity.visualstudio.com/idea/869998/enable-vs-code-users-with-github-accounts-to-upvot.html

UPDATE: Upvotes to this GitHub issue are sufficient now.

shehabattia96 commented 4 years ago

@sean-mcmanus Thanks for creating a ticket and for letting me know! HNY!

sean-mcmanus commented 4 years ago

A potential workaround is to use

#if __INTELLISENSE__
#pragma diag_suppress 2486
#endif
boid-com commented 3 years ago

Great solution, is this documented anywhere?

sean-mcmanus commented 3 years ago

I don't know. Might not be. I'm not sure where a good place would be to document that though.

boid-com commented 3 years ago

On this page: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools