simplecpp icon indicating copy to clipboard operation
simplecpp copied to clipboard

Cppcheck 2.6 fails to handle / ## / in macro definitions within .cpp files from all of my Visual C++ projects

Open Mike4Online opened this issue 4 years ago • 0 comments

I just installed Cppcheck 2.6, and it fails to handle / ## / in macro definitions within .cpp files from all of my Visual C++ projects. I get errors such as

failed to expand 'LOGVERBOSE', Invalid ## usage when expanding 'LOGVERBOSE'.

In my code the macro is defined as follows:

#define LOGVERBOSE / ## /

The end result is the macro becomes defined as //, so any statement beginning with LOGVERBOSE is commented out. This is a handy technique for enabling and disabling logging statements.

Originally posted by @Mike4Online in https://github.com/danmar/simplecpp/issues/141#issuecomment-944829805

Danmar's response:

ok I guess it is a visual studio extension. so we should try to handle it. Could you open a new issue about it.

Note that Microsoft's C preprocessor now has two modes: traditional and conforming. The traditional mode is what includes Microsoft-specific behaviors, including support for / ## / being translated into //. This specific behavior is documented by Microsoft as a Macro comment, at the following page...

https://docs.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-160#macro-comments

Mike4Online avatar Oct 18 '21 16:10 Mike4Online