cmisrapc-lint

PC-lint suppress error within `/* ... */` block comment


I've got a doc comment like:

/**
 * See [datasheet][1] for details.
 *
 * [1]: https://example.com
 */
void my_func(void);

And PC-lint is upset because note 9259: C comment contains '://' sequence [MISRA 2012 Rule 3.1, required]. I want to disable this warning/note.

From the PC-lint manual for e9259:

[9259] C comment contains '://' sequence

Message 9059 reports on cases where a C comment contains what may be a C++ comment, e.g. the sequence ’//’. Because including URLs inside of comments is a common practice, message 9059 is not issued when the ’//’ sequence is immediately preceded by a ’:’ to prevent the message from being issued in cases such as:

/* See http://www.gimpel.com for details */

This message (ie, message 9529) fills the gap by reporting on the instances not reported by 9059.

And the PC-lint manual for e9059:

[9059] C comment contains C++ comment

A C++-style comment was seen inside a C-style comment. This can be confusing.

I've tried appending !e9259 to the offending line, as well as lint !e9259, but they don't work. I can't do something like /*lint !e9259 because PC-lint then complains about /* in a block comment. For the same reason //lint !e9259 won't work. I also can't wrap the doc comment in /*lint -save -e9259*/ and /*lint -restore*/ because that will break doxygen's parsing of the function's doc comment.


Solution

  • The original MISRA C:2012 release from year 2012 had a hiccup here in regards to URLs. This has since then been fixed in technical corrigendums (TC).

    MISRA C:2012 including all TC (aka MISRA C:2023), rule 3.1 has the following exception to the rule:

    1. Uniform resource identifiers, of the form {scheme}://{path}, are permitted within comments.

    There is even an explicit example of an URL within comments as an acceptable exception to rule 3.1! So your code is MISRA compliant in this regard.

    The purpose of rule 3.1 is to block "commented-out code" from being present in production builds, nothing else. And so a :// sequence is fine, a // C99 comment is not.

    So either PC Lint is broken or you are using an old version which isn't updated to the current MISRA C. Both you and PC Lint should be using MISRA C:2023 which is the same document as MISRA C:2012 but with all technical corrigendums included.