MISRA C++:2008 Rule 3-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 do not see it, refer to Coding Standard Violations Not Displayed.

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
Introduced in R2013b