Main Content

AUTOSAR C++14 Rule A0-1-6

There should be no unused type declarations

Description

Rule Definition

There should be no unused type declarations.

Rationale

If you declare a type but do not use it, determining if the type is redundant or left unused by mistake is difficult when you review your code.

For example, if you declare an enumerated data type to store some specialized data, but then use an integer type to store the data, the unused type can indicate a coding error.

Polyspace Implementation

Polyspace® reports a violation of this rule if your code contains unused local types.

As an exception, Polyspace does not report a violation if you define the unused type with public access in a template class.

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

expand all

In this example, you do not use the enumerated type switchValue.Because you declare the type but do not use it, Polyspace reports a violation.

enum switchValue {low, medium, high}; //Noncompliant

void operate(int userInput) {
    switch(userInput) {
        case 0: // Turn on low setting
                 break;
        case 1: // Turn on medium setting
                 break;
        case 2: // Turn on high setting
                 break;
        default: // Return error
    }
}

Perhaps the intention was to use the type as switch input like this.

enum switchValue {low, medium, high}; //Compliant

void operate(switchValue userInput) {
    switch(userInput) {
        case low: // Turn on low setting
                   break;
        case medium: // Turn on medium setting
                     break;
        case high: // Turn on high setting
                   break;
        default: // Return error
    }
}

When developing template classes, you might declare a public typedef that is used by the clients of the template, even if the template itself does not use the typedef. In such a case, Polyspace does not report a violation if a public typedef remains unused in a template. For instance, in this code, Polyspace does not report a violation for the unused type T*.

template<typename T>
  class myContainerIterator {
    public:
      using pointer = T*;              // Compliant
      typedef T* Pointer;              // Compliant

    //...
  };

Check Information

Group: Language Independent Issues
Category: Advisory, Automated

Version History

Introduced in R2019a

expand all