AUTOSAR C++14 Rule A14-1-1
A template should check if a specific template argument is suitable for this template
Since R2021b
Description
Rule Definition
A template should check if a specific template argument is suitable for this template.
Rationale
A template defines the operations of a class or function for generic template types. If
these operations require that the template types have specific characteristics, for instance
the data type must be copy constructible, check the template arguments to ensure that they
are suitable and have the required characteristics. Typically, you use
static_assert
assertions to perform this check at compile time, for
instance, static_assert(std::is_copy_constructible<T>)
.
Polyspace Implementation
Polyspace® flags template classes, structs, unions, and functions unless one of the following is true:
The template contains at least one
static_assert
assertion, even if that assertion does not test the characteristics of the template parameters.The template is explicitly fully specialized even when it does not contain any
static_assert
assertions.
Polyspace does not flag template declarations.
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: Templates |
Category: Advisory, Non-automated |