Hello,
I'm getting a false positive on file guard. I have a file, Events.h with the follow file guard:
#ifndef Events_H#define Events_H
and I'm getting the MISRA error:
..\Sources\Events.h:29:0: style: Required. #define and #undef shall not be used on a reserved identifier or reserved macro name. [misra-c2012-21.1]
Thanks,
Amir
Last edit: Amir 2020-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Running misra.py from the latest Cppcheck from git master gives me the following output:
Checkingaddons/test/misra/21-1.c.dump...Checkingaddons/test/misra/21-1.c.dump,config...[addons/test/misra/21-1.c:3](style)misraviolation(use--rule-texts=<file> to get proper output) (Undefined) [misra-c2012-2.7]MISRArulesviolationsfound:Undefined:1MISRArulesviolated:misra-c2012-2.7(-):1
Edit: I also found this line in your output: ..\Sources\Events.h:29:0:. , which indicates that there is an error in 29 line. Are you sure that this error caused by include guards?
Last edit: Georgiy Komarov 2020-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the quick reply. There are comments above the file guards which is why the error is occurring at line 29. This file is auto-generated. Here is what it looks like:
/* ###################################################################** Filename : Events.h** Project : kds_volta_mcu** Processor : SKEAZN64MLC2** Component : Events** Version : Driver 01.00** Compiler : GNU C Compiler** Date/Time : 2020-03-26, 14:07, # CodeGen: 0** Abstract :** This is user's event module.** Put your event handler code here.** Contents :** Cpu_OnNMIINT - void Cpu_OnNMIINT(void);**** ###################################################################*//*!** @file Events.h** @version 01.00** @brief** This is user's event module.** Put your event handler code here.*//*!** @addtogroup Events_module Events module documentation** @{*/
#ifndef__Events_H
#define__Events_H/* MODULE Events */
...
...
#endif
Version:
Cppcheck 1.90
Last edit: Amir 2020-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this case, the addon is absolutely right. This is a violation of the rule 21.1.
According to MISRA document, #define and #undef directives should not be used with the following identifiers:
• Identifiers or macro names beginning with an underscore;
• Identifiers in file scope described in Section 7, “Library”, of The Standard;
• Macro names described in Section 7, “Library”, of The Standard as being defined in a standard header.
C99 standard (ISO/IEC 9899:TC3) declares reserved identifiers in ch. 7.1.3 as the following:
— All identifiers that begin with an underscore and either an uppercase letter or another
underscore are always reserved for any use.
The rationale is that reserved identifiers are used internally in the implementation of standard library, so you should avoid using them if possible.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'm getting a false positive on file guard. I have a file, Events.h with the follow file guard:
and I'm getting the MISRA error:
..\Sources\Events.h:29:0: style: Required. #define and #undef shall not be used on a reserved identifier or reserved macro name. [misra-c2012-21.1]
Thanks,
Amir
Last edit: Amir 2020-04-17
Which version of Cppcheck do you use?
I can't reproduce this bug with the following code:
Running misra.py from the latest Cppcheck from git master gives me the following output:
Edit: I also found this line in your output: ..\Sources\Events.h:29:0:. , which indicates that there is an error in 29 line. Are you sure that this error caused by include guards?
Last edit: Georgiy Komarov 2020-04-17
Thanks for the quick reply. There are comments above the file guards which is why the error is occurring at line 29. This file is auto-generated. Here is what it looks like:
Version:
Cppcheck 1.90
Last edit: Amir 2020-04-17
In this case, the addon is absolutely right. This is a violation of the rule 21.1.
According to MISRA document, #define and #undef directives should not be used with the following identifiers:
C99 standard (ISO/IEC 9899:TC3) declares reserved identifiers in ch. 7.1.3 as the following:
The rationale is that reserved identifiers are used internally in the implementation of standard library, so you should avoid using them if possible.
Thank you! That clears it up. I've tried to suppress the error but can't seem to do so inline:
Regards,
Amir