Main Content

AUTOSAR C++14 Rule M3-3-2

If a function has internal linkage then all re-declarations shall include the static storage class specifier

Description

Rule Definition

If a function has internal linkage then all re-declarations shall include the static storage class specifier.

Rationale

If a function declaration has the static storage class specifier, it has internal linkage. Subsequent redeclarations of the function have internal linkage even without the static specifier.

However, if you do not specify the static keyword explicitly, it is not immediately clear from a declaration whether the function has internal linkage.

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

static void func1 ();
static void func2 ();

void func1() {}  //Noncompliant
static void func2() {}

In this example, the function func1 is declared static but defined without the static specifier.

Check Information

Group: Basic Concepts
Category: Required, Automated

Version History

Introduced in R2019a