4.1 Project MISRA C:2012 deviations
This page contains all project deviations, defined as deviations from MISRA C guidelines in a particular class of circumstances, for all files in the USB Device Stack for 8-bit AVR® MCUs.
Advisory: misra-c2012-2.5
Justification: False positive - This deviation explicitly only concerns the false positive on include guard macros. While rule 2.5 does not explicitly specify an exception for include guards, it is deemed that the wording of the rule effectively confirms that this is a false positive. The standard does not specify what "unused" means. An include guard macro is deemed as used as it does, in fact, have a function when used as an include guard. Moreover, the rationale for rule 2.5 states: "If a macro is declared but not used,
then it is unclear to the reviewer if the macro is redundant or has been left unused by mistake". It is assumed that no code reviewer would think it is unclear whether or not an include guard is redundant. Finally, MISRA C:2012 Directive 4.10 states that: "Precautions shall
be taken in order to prevent the contents of a header file being included more than once" and shows the usage of include guards as an example of compliance. Thus, the false positive can be suppressed for all include guards that trigger this false positive, even if the header-file is only included in one place. The latter reasoning is added because one cannot always know in advance whether or not a header file will be included more than once and include guards should thus be added regardless. Also, see thread-1317 on the official MISRA forum webpage for further confirmation that this is a false positive.
Include guard example:
#ifndef FOO_H // cppcheck-suppress misra-c2012-2.5 #define FOO_H //contents of file #endif //FOO_H