AutosarC++18_10-A2.10.1

An identifier declared in an inner scope shall not hide an identifier declared in an outer scope

Required inputs: IR

Avoid names in inner scopes shadowing names in outer scopes. Note: for C++ it is advised to disable the configuration option distinguish_name_spaces.
Bad code
int foo(int i) {
    int i = 0; // Non-Compliant - variable hides parameter
    return i;
}
Bad code (distinguish_name_spaces disabled)
class C { int i; // field C(int i) { this->i = i; } // Compliant in constructor void f(int i) { this->i = i; } // Non-Compliant - parameter hides field };

Possible Messages

Key

Text

Severity

Disabled

hiding

{} hides {}

None

False

Options

allow_hiding_if_condition_in_else

allow_hiding_if_condition_in_else : bool = False

Allow hiding a variable declared in the condition of an if-statement within the else block. This is useful to allow re-use of the same variable name in a chain of else-if using C++17 variable declarations in the if-statement:
  if (auto x = get(1); x.ok()) {}
  else if (auto x = get(2); x.ok()) {}
This option causes the rule to act as if variables declared in the if condition were only visible in the then-branch.
 

allow_in_classes

allow_in_classes : bool = True

Whether identifiers in local classes can hide surrounding ones.
 

allow_in_lambdas

allow_in_lambdas : bool = True

Whether identifiers in lambdas can hide surrounding ones.
 

allow_in_namespaces

allow_in_namespaces : bool = True

Whether identifiers in namespaces can hide surrounding ones.
 

allow_parameter_in_function_declaration

allow_parameter_in_function_declaration : bool = False

Whether identifiers of parameters in function declarations may hide surrounding ones, given the function declaration uses a different identifier for the same parameter that does not hide a surrounding one.
 

check_inheritance_hiding

check_inheritance_hiding : bool = False

Whether to check for hiding by inheritance.
 

check_nested_classes

check_nested_classes : bool = False

Whether symbols from inner classes should be reported as hiding symbols of outer classes.
 

constructor_parameters_not_hiding_fields_in_initializer_list

constructor_parameters_not_hiding_fields_in_initializer_list : bool = False

Consider use of constructor parameters in the constructor initializer list not as hiding, when parameter name is also a class field name.
 

distinguish_name_spaces

distinguish_name_spaces : bool = False

Whether C name spaces should be distinguished.
 

hiding_entities

hiding_entities : set[bauhaus.ir.LIR_Class_Name] = {'Field', 'Parameter', 'Typedef_Type', 'Variable'}

LIR node types to consider symbols that hide other symbols.
 

maxlen

maxlen : int | None = None

Number of significant characters (or None).
 

tolerate_constructor_parameters_hiding_fields

tolerate_constructor_parameters_hiding_fields : bool = False

Allow constructor parameters to hide fields
 

tolerate_function_prototype_argument_hiding

tolerate_function_prototype_argument_hiding : bool = False

Whether to tolerate arguments of a function prototype, that itself is a function argument, that have the same identifier as a argument of the outer function. If true, the rule will still report cases, where argument identifiers match up and the function prototype refers to arguments of the outer function (e.g. by decltype()).
 

tolerate_hiding_private_members

tolerate_hiding_private_members : bool = False

Whether to tolerate hiding private members of base classes.
 

tolerate_macro_local_identifier

tolerate_macro_local_identifier : bool = False

Whether an identifier being local to a macro is allowed to hide identifiers from outside the macro.