AUTOSAR C++14 Rule A14-7-1
A type used as a template argument shall provide all members that are used by the template
Since R2021b
Description
Rule Definition
A type used as a template argument shall provide all members that are used by the template.
Rationale
A template can define operations on a generic type through one or more member variables or member functions. If the type that you use to instantiate the template does not provide all of the members that the template uses, your program might be ill-formed and might contain syntax or semantic errors.
For example, in the following code, template TmplClass
declares a
member function someProperty()
but type myType
does
not. The instantiation of TmplClass
by using myType
is
noncompliant and, as a result of the missing someProperty()
function,
inst.func();
causes a compilation
error.
template <typename T> class TmplClass { public: void func() { T t; t.someProperty(); } }; struct myType { }; void Instance() noexcept { TmplClass<myType> inst; //Non-compliant // inst.func(); //compilation error, struct myType has no member function someProperty() }
Polyspace Implementation
Polyspace® flags
class
,struct
, orunion
template instantiations when the template parameter does not contain all of the members that the template uses.If you review results in the Polyspace desktop or web interfaces, in the template definition, the software highlights the members that are missing from the template parameter.
Polyspace does not flag:
Function template instantiations.
Template instantiations that use an incomplete type as the template parameter.
Template instantiations that use a template parameter, where the missing member is a member type (nested type) or a member template.
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 R2021b