AUTOSAR C++14 Rule A14-7-2
Template specialization shall be declared in the same file (1) as the primary template (2) as a user-defined type, for which the specialization is declared
Since R2020a
Description
Rule Definition
Template specialization shall be declared in the same file (1) as the primary template (2) as a user-defined type, for which the specialization is declared.
Rationale
Observing this rule avoids situations where the behavior is undefined. For instance, if a compiler sees a partial specialization of a template after it has instantiated the template, the behavior is undefined. If you specialize a template in the same file as the template, this situation is less likely to occur.
You can also easily extend compile-time interfaces through specialization since the template and its specialization are in the same file and part of the same translation unit. The same reasoning applies to the requirement that a template specialization must be in the same file as the type for which the template is specialized.
Polyspace Implementation
The checker checks each template specialization and raises a violation if:
The specialization is not in the same file as the template that is specialized.
The specialization is not in the same file as the definition of the user-defined type for which the template is specialized.
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: Required, Automated |
Version History
Introduced in R2020a