<p dir="ltr">In clang-tidy we're trying to provide natural ways to mute diagnostics (e.g. warnings related to implicit casts can be suppressed by adding the corresponding explicit cast). It's the preferred way, but it's not always possible, so additionally clang-tidy supports `// NOLINT` suppression comments without a way to silence specific diagnostics/checks. `// NOLINT` mutes all diagnostics on the same line.</p>
<p dir="ltr"><a href="https://github.com/google/styleguide/tree/gh-pages/cpplint">Cpplint</a>, where we took the idea from, additionally supports `// NOLINT(category)` that allows targeted suppression of diagnostics, and `// NOLINTNEXTLINE` (with an optional `(category)` as well), which mutes diagnostics on the following line.</p>
<p dir="ltr">NOLINT was a reasonable solution for clang-tidy, since many cpplint checks are implemented in clang-tidy as well and suppressions (where needed by both tools) should not be repeated with a different syntax.</p>
<p dir="ltr">I'm not particularly interested in significantly improving suppression mechanisms, since in most cases it's better to either improve the analysis or modify the code. The frequency of suppressions should stay low to avoid warning blindness and letting the code with suppression comments.</p>
<p dir="ltr">For compiler diagnostics I'm against introducing a comment-based suppression system at all. It's not the compiler's business to analyze comments.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On 18 Aug 2016 10:17 AM, "Gábor Horváth" <<a href="mailto:xazax.hun@gmail.com">xazax.hun@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Hi!<br><br></div>In the CodeChecker tool (<a href="https://github.com/Ericsson/codechecker" target="_blank">https://github.com/Ericsson/<wbr>codechecker</a>) we support suppressing false positive bugs as a post processing step. After all the issues were reported, CodeChecker filters out the suppressed ones, and those will not be displayed to the user. <br><br></div>In our experience, however, and external tool only suppression suppport is not sufficient for certian reasons:<br></div>* When a checker generates a sink node during analysis, the rest of the path will not be covered by the Static Analyzer. Unfortunately, if the user suppress the bug in an external tool, the coverage will not get better. This way false positive results can hide true positive results regardless of suppression.<br></div>* The compiler could do better job diagnosing ill formed suppressions (invalid source range, typo in checker name etc).<br></div><div>* Tools that are developed on top of the compiler need not to introduce their own customized solution for suppression. <br><br></div><div>It is beneficial to have a suppression format that is standard across all clang tools. So the same format could be used to:<br></div><div>* Suppress clang warnings<br></div><div>* Suppress clang static analyzer warnings<br></div><div>* Suppress clang tidy warnings<br><br></div><div>There are two main approaches to suppress warnings that I can think of right now:<br><br></div><div>Suppress using comments (or pragma):<br></div><div>* This is a good solution for code evolution. The comments are moving together with the code. Edits are less likely to invalidate comments.<br></div><div>* This is an intrusive solution, the source code needs to be changed to suppress an issue. This is both good, because the suppressions are version controlled and bad, because suppressing in 3rd party libraries might be problematic.<br></div><div>* For path sensitive checks, it is not always self evident at which point of the path should a suppression comment be added. <br><br><br></div><div>Suppress using hashes:<br></div><div>* It is hard to come up with a reliable hash to identify bugs. There always might be corner cases when the hashes of different bugs collide or the hash of a bug changes due to an edit that in fact should not affect the bug.<br></div><div>* It is non intrusive.<br></div><div>* The user do not need to think about at which point should the suppression comment be inserted.<br><br><br></div><div>I would suggest the suppress comment road.<br></div><div>The syntax could be something like:<br></div><div>// clang suppress warning-or-checker-name [optional line offset][optional column range] [comment]<br><br></div><div>The warning-or-checker-name could be a regex, so multiple checks can be suppressed at the same time.<br></div><div>Column ranges are useful when multiple errors are reported for the same line.<br></div><div>Line offsets are useful when one do not want to break the flow of a multi line code snippet with a comment, so this way warnings could be suppressed without too much negative effects on the readability.<br></div><div>Comment is for documentation purposes, the user can document why does she think that this is a false positive.<br><br></div><div>What do you think?<br><br></div><div>Regards,<br></div><div>Gábor<br></div><div><br></div><div><br><br></div><div><br></div></div>
</blockquote></div></div>