2

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.

7
  • 2
    Isn't cppcheck for C++? Commented Mar 2, 2020 at 14:56
  • 3
    The C++/CLI Type^ syntax does not exist in C++, so this is certainly what CppCheck is confused with. Commented Mar 2, 2020 at 14:57
  • 1
    When asking questions about errors, please always include the actual errors you get, copy-pasted as text in full and complete. Commented Mar 2, 2020 at 14:57
  • 3
    @ViktorBe No, the code shown isn't C++ code. That is also what cppcheck is telling you actually. Commented Mar 2, 2020 at 15:05
  • 1
    As others have already pointed out, Cppcheck doesn't support C++/CLI. Try to use other analyzers. For example, PVS-Studio supports the analysis of C++/CLI and C++/CX (WinRT). Commented Mar 3, 2020 at 7:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.