AutosarC++18_03-A2.10.5

An identifier name of a function with static storage duration or a non-member object with external or internal linkage should not be reused

Required inputs: IR

Rationale

Regardless of scope, no identifier with static storage duration should be re-used across any source files in the project. This includes objects or functions with external linkage and any objects or functions with static storage class specifier. While the compiler can understand this, the possibility exists for the developer or development tool to incorrectly associate unrelated variables with the same name.

Note: This rule does not apply to objects without linkage, e.g. function local static objects.

Example
//% $Id: A2-10-5.cpp 305382 2018-01-26 06:32:15Z michal.szczepankiewicz $
#include <cstdint>
// f1.cpp
namespace n_s1 {
static std::int32_t globalvariable = 0;
}
static std::int32_t filevariable = 5; // Compliant - identifier not reused
static void Globalfunction();

// f2.cpp
namespace n_s1 {
// static std::int32_t globalvariable = 0; // Non-compliant - identifier reused
static std::int16_t modulevariable = 10; // Compliant - identifier not reused
} // namespace n_s1
namespace n_s2 {
static std::int16_t modulevariable2 = 20;
}
static void Globalfunction();             // Non-compliant - identifier reused
static std::int16_t modulevariable2 = 15; // Non-compliant - identifier reused
See Also
  • MISRA C++ 2008 [6]: advisory 2-10-5 The identifier name of a non-member object or function with static storage duration should not be reused.

Possible Messages

Key

Text

Severity

Disabled

reused_global_function_name

Name of object or function with static storage duration reused.

None

False

reused_global_variable_name

Name of object or function with static storage duration reused.

None

False

Options

allow_overloads

allow_overloads : bool = True

If set to true, overloads are not reported as violations.
 

allow_reusing_function_name_for_locals

allow_reusing_function_name_for_locals : bool = False

Whether the reuse of a function name (with static storage duration) as the name of local variables should be allowed.
 

allow_static_no_linkage

allow_static_no_linkage : bool = True

Whether to allow same identifiers for static objects without linkage (e.g. function local static objects).
 

detect_different_compilation_units_overloads

detect_different_compilation_units_overloads : bool = False

If set to true, functions with the same name and in the same scope are detected as overloads even if they are not part of the same compilation unit.
 

func_filter

func_filter : typing.Callable[[bauhaus.ir.Node], bool] | None = None

Restricts which functions are considered.
 

include_local_variables

include_local_variables : bool = True

Whether local static variables should be included in the check.
 

use_unqualified_names

use_unqualified_names : bool = True

If set to True, ns1::Type is considered equal to ns2::Type.
 

var_filter

var_filter : typing.Callable[[Variable], bool] | None = None

Restricts which variables are considered.