To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
V688. The 'foo' local variable possesse…
Analyzer Diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Diagnosis of micro-optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
MISRA errors
AUTOSAR errors
Additional information
Contents

V688. The 'foo' local variable possesses the same name as one of the class members, which can result in a confusion.

March 4, 2014

The analyzer has detected an issue when the name of a local variable coincides with the name of a class member. It is not an error in most cases, but such code may be EXTREMELY dangerous as it is exposed to errors that may occur after refactoring. The programmer assumes he is working with a class member while actually using the local variable.

An example of the error:

class M
{
  int x;
  void F() { int x = 1; foo(x); }
  ....
};

The class contains a member named 'x'. The same name is used for the local variable in the F() function.

The error is clearly seen in a small sample like that, so you may find the V688 diagnostic uninteresting. But when you work with large functions, such a careless choice of names for variables may cause much trouble to developers maintaining the code.

We just need to choose another name for the local variable to avoid the error:

class M
{
  int x;
  void F() { int value = 1; foo(value); }
  ....
};

Another solution is to use the 'm_' prefix in the names of class members:

class M
{
  int m_x;
  void F() { int x = 1; foo(x); }
  ....
};

The analyzer generates this warning in certain cases only. It employs certain heuristics mechanisms to avoid false positives. For example, it won't react to the following code:

class M
{
  int value;
  void SetValue(int value) { this->value = value; }
  ....
};

This diagnostic is classified as:

  • CERT-DCL01-C

You can look at examples of errors detected by the V688 diagnostic.

This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept