AUTOSAR C++14 Rule A16-6-1
#error directive shall not be used
Since R2020a
Description
Rule Definition
#error directive shall not be used.
Rationale
You typically use the #error
directive by combining it with a
#if
or similar directive to make the compilation fail and issue a
message when a condition is not met. However, you cannot apply #error
to
templates. Preprocessor directives do not obey linkage, type checker, overloading and other
C++ features, and #error
will not be evaluated as a per-instance
template deduction.
Instead, use static_assert
for compile-time error checking. Static
assertions provide all the benefits of C++ features and make the code clearer.
Polyspace Implementation
Polyspace® flags all uses of the #error
directive.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Check Information
Group: Preprocessing directives |
Category: Required, Automated |
Version History
Introduced in R2020a