V601. An odd implicit type casting.

The analyzer has detected an odd implicit type conversion. Such a type conversion might signal an error or carelessly written code.

Let's consider the first example.

std::string str;
bool bstr;
str = true;

Any programmer will be surprised on seeing an assignment of the 'true' value to a variable of the 'std::string' type. But this construct is quite permissible and working. The programmer just made a mistake here and wrote a wrong variable.

This is the correct code:

std::string str;
bool bstr;
bstr = true;

Consider the second example:

bool Ret(int *p)
  if (!p)
    return "p1";

The string literal "p1" turns into the 'true' variable and is returned from the function. It is a very odd code.

We cannot give you general recommendations on fixing such code, since every case must be considered individually.

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-704.

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

Bugs Found

Checked Projects
Collected Errors
12 668