C and C++


LANG.PREPROC.INVALID : Invalid Preprocessor Directive

Summary

A line starts with # but is not a valid preprocessing directive.

Properties

Class Name Invalid Preprocessor Directive
Significance reliability
Mnemonic LANG.PREPROC.INVALID
Categories
MisraC2023 MisraC2023:20.13 A line whose first token is # shall be a valid preprocessing directive
Misra2012 Misra2012:20.13 A line whose first token is # shall be a valid preprocessing directive
AUTOSARC++14 AUTOSARC++14:A16-0-1 The pre-processor shall only be used for unconditional and conditional file inclusion and include guards, and using the following directives: (1) #ifndef, (2) #ifdef, (3) #if, (4) #if defined, (5) #elif, (6) #else, (7) #define, (8) #endif, (9) #include.
  AUTOSARC++14:M16-0-8 If the # token appears as the first token on a line, then it shall be immediately followed by a pre-processing token.
MisraC++2008 MisraC++2008:16-0-8 If the # token appears as the first token on a line, then it shall be immediately followed by a preprocessing token.
MisraC++2023 MisraC++2023:19.0.1 A line whose first token is # shall be a valid preprocessing directive
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Invalid Preprocessor Directive"

Example

/* following is ok: inside a comment*/
/*
#in a comment
*/

#define AAA 2

#ifndef AAA
#define BBB 1
#else1           /* 'Invalid Preprocessor Directive' warning issued here */
#define CCC 2
#endif

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.