Anonymouse
Anonymouse

Reputation: 945

How to disable a CodeSonar warning in C++

The title says it all... I have project which needs to MISRA 2004 clean, and the company was told CodeSonar was a good tool to do the static analysis.

On other static analysis tools you can add a magic comment to disable analysis for the next line\block of code, (PC-Lint is //lint -esym(42), CStat uses #pragma cstat_suppress="MISRAC++2008-6-4-1") but CodeSonar doesn't appear to have any equivalent - please tell me I'm wrong!

I've seen mention of a // NOSONAR but that does not appear work on CodeSonar 5.1

(I'm rapidly coming to the conclusion CS is a pile junk written by people who have never programmed in the real world with SVN and multiple programmers, where disabling warnings in a fancy UI goes down the swanny when you're merging branches into trunk and all the line numbers change.)

Upvotes: 3

Views: 3291

Answers (2)

Penghe Geng
Penghe Geng

Reputation: 14631

Since CodeSonar 4.0.0, there is a new filter option added to WARNING_FILTER: line_content that allows you add a "magic comment".

Add the following line to your proj_name.conf:

WARNING_FILTER += line_contents:"NOLINT"

This will disable warnings for a line ending with // NOLINT

Upvotes: 2

ACG
ACG

Reputation: 11

Check out the documentation and examples for configuration variable WARNING_FILTER.

CodeSonar doesn't provide an out-of-the-box // NOSONAR in any version. However, one of the available rule forms for WARNING_FILTER will allow you to implement one for yourself if that is the approach you decide to take.

If you need to suppress a specific warning, you should be able to annotate the warning directly. The signatures that are used to correlate 'the same' warning between analyses do not depend on line number or other code features that are highly likely to change.

Upvotes: 1

Related Questions