Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2023-6.4.1

In this section:
Synopsis

(Required) A variable declared in an inner scope shall not hide a variable declared in an outer scope

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

There are identifier names that are not distinct from other names in an outer scope. This check is identical to MISRAC++2008-2-10-2.

Coding standards
MISRA C++ 2008 2-10-2

(Required) Identifiers declared in an inner scope shall not hide an identifier declared in an outer scope.

Code examples

The following code example fails the check and will give a warning:

extern int f2(void);
extern int f3(void);
extern int  n01_param_hides_var;
extern int  n02_var_hides_var;
void        n03_var_hides_function (void) {}

union       n04_var_hides_union_tag {
  int v1;
  unsigned int v2;
};
enum        n05_var_hides_enum_tag {
            n06_var_hides_enum_const,
};
extern int  n07_type_hides_var;

struct      n08_var_hides_class1 {
  int       n09_var_does_not_hides_mem;
};

class       n10_var_hides_class2 {
  int cm1;
};

void f1(int n01_param_hides_var) {
  int       n02_var_hides_var;
  int       n03_var_hides_function;
  int       n04_var_hides_union_tag;
  int       n05_var_hides_enum_tag;
  int       n06_var_hides_enum_const;

  switch(f2()) {
  case 1: {
    typedef int n07_type_hides_var;
    int n08_var_hides_class1;
    int n09_var_does_not_hides_mem;
    int n10_var_hides_class2;
    do {
      struct    n11_var_hides_struct_tag {
	int ff1;
      } b;
      if(f3()) {
	int     n11_var_hides_struct_tag = 1;
      }
    } while(f2());
  }
  }
}

namespace ns1 {
  int   n12_var_hides_var_ns;
  void f4(void) {
    int n12_var_hides_var_ns;
  }
}

The following code example passes the check and will not give a warning about this issue:

namespace ns1 {
  int   n16_var_hides_var_ns;
}

namespace ns2 {
  void f2(void) {
    int n16_var_hides_var_ns;
  }
}