Search code examples
c++-clicppcheck

Cppcheck syntax error code smell by C++/CLI


New version of cppcheck found two major code smells named "syntax error" in following old lines of code:

System::Reflection::Assembly^ Foo(Object^ /* obj */, System::ResolveEventArgs^ args)
        {...}

and

catch (System::Exception^ /*e*/)

Errortext:

Cppcheck cannot tokenize the code correctly.

Any idea how to fix them? Is something wrong with the C++/CLI syntax?

It looks like a false positive for me, as the code compiles and works for a long time.


Solution

  • Any idea how to fix them?

    There is nothing you can do. C++/CLI is a dialect of C++, it is not standard C++. cppcheck works only with standard C or C++, so it will fail to understand C++/CLI code and thus give you the diagnostic you see. You'll need to exclude the source files that use C++/CLI code from your cppcheck check to avoid these errors.