AutosarC++19_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
| Level | advisory |
|---|---|
| Target | design / implementation |
| Enforcement | automated |
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_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 [7]: 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¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allow_overloads¶
allow_overloads : bool = True
allow_reusing_function_name_for_locals¶
allow_reusing_function_name_for_locals : bool = False
allow_static_no_linkage¶
allow_static_no_linkage : bool = True
detect_different_compilation_units_overloads¶
detect_different_compilation_units_overloads : bool = False
func_filter¶
func_filter : typing.Callable[[bauhaus.ir.Node], bool] | None = None
include_local_variables¶
include_local_variables : bool = True
use_unqualified_names¶
use_unqualified_names : bool = True
var_filter¶
var_filter : typing.Callable[[Variable], bool] | None = None