AUTOSAR C++14 Rule M16-1-2
All #else, #elif and #endif pre-processor directives shall reside in the same file as the #if or #ifdef directive to which they are related
Description
Rule Definition
All #else, #elif and #endif pre-processor directives shall reside in the same file as the #if or #ifdef directive to which they are related.
Rationale
You use preprocessor directives, such as
#if...#elif...#else...#endif, to conditionally include or exclude blocks
of code. If the different branches of such a directive reside in different source files, the
code can be confusing. If all the branches are not included in a project, the code might
behave in unexpected ways. To avoid confusion and unexpected behavior, keep the branches of
a conditional preprocessor directive within the same source file.
Polyspace Implementation
Polyspace® raises a violation of this rule if either of these conditions are true:
A corresponding
#ifdirective cannot be found within a source file for every#else,#elif, or#endifdirective.A corresponding
#endifdirective cannot be found within a source file for every#ifdirective.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Preprocessing Directives |
| Category: Required, Automated |
Version History
Introduced in R2019a