AutosarC++19_03-A14.5.2¶
Class members that are not dependent on template class parameters should be defined in a separate base class
Required inputs: IR
| Level | advisory |
|---|---|
| Target | design |
| Enforcement | partially-automated |
Rationale
Having non-dependent members in a class template can lead to unnecessary template instantiations and potential code bloat. It is therefore preferred to move those members to a non-dependent base class so they can be used without any template instantiation.
Example
// $Id: A14-5-2.cpp 323444 2018-06-22 14:38:18Z christof.meerwald $
#include <cstdint>
template<typename T>
class A
{
public:
enum State // Non-Compliant: member doesn’t depend on template parameter
{
State1,
State2
};
State GetState();
};
class B_Base
{
public:
enum State // Compliant: not a member of a class template
{
State1,
State2
};
};
template<typename T>
class B : B_Base
{
public:
State GetState();
};
See Also
- C++ Core Guidelines [11]: T.62: Place non-dependent class template members in a non-templated base class
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
non_dependent_member |
Class member does not depend on template parameters. |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.