Main Content

AUTOSAR C++14 Rule A7-1-4

The register keyword shall not be used

Description

Rule Definition

The register keyword shall not be used.

Rationale

The register keyword will be removed from the C++ language in a future release, resulting in code that either no longer compiles or that exhibits undefined behavior. Most compilers ignore the register specifier and assign registers themselves. By relying on the presence of specific objects in the processor register, the code might behave in unexpected ways.

To resolve this issue, remove the register keyword.

Polyspace Implementation

Polyspace® flags the declaration of an object if its storage type is register.

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

#include <cstdint>  

int main() {  
  register std::int32_t x = 7; //Noncompliant  
  std::int32_t y = 7; //Compliant  
  return 0;  
}

In this example, Polyspace flags the use of the keyword register.

Check Information

Group: Declaration
Category: Required, Automated

Version History

Introduced in R2019a