The analyzer has detected two functions with identical implementations. Although having two identical functions is not an error, they should still be reviewed.
The diagnostic rule detects the following error types:
class Point
{
...
float GetX() { return m_x; }
float GetY() { return m_x; }
};
A typo causes two logically different functions to perform the same actions. The fixed code:
float GetX() { return m_x; }
float GetY() { return m_y; }
In the example, the identical bodies of the GetX() and GetY() functions indicate an error. However, issuing warnings for all identical functions could result in many false positives. Therefore, the analyzer has a number of exceptions where a warning about identical function bodies is not required.
Some examples of exceptions:
bool IsXYZ() { return true; };int Get() { static int x = 1; return x++; };However, in some cases the analyzer may mistakenly determine identical function bodies as an error, even if they are not dangerous:
PolynomialMod2 Plus(const PolynomialMod2 &b) const
{return Xor(b);}
PolynomialMod2 Minus(const PolynomialMod2 &b) const
{return Xor(b);}
You can suppress false positives using several approaches:
//-V524 type to suppress false-positive warnings. The last approach is often the best because it reduces the amount of code and makes it easier to support. You need to edit only one function instead of both.
The following is a real-world example where calling one function from another would be beneficial:
static void PreSave(void) {
int x;
for(x=0;x<TotalSides;x++) {
int b;
for(b=0; b<65500; b++)
diskdata[x][b] ^= diskdatao[x][b];
}
}
static void PostSave (void) {
int x;
for(x=0;x<TotalSides;x++) {
int b;
for(b=0; b<65500; b++)
diskdata[x][b] ^= diskdatao[x][b];
}
}
The code can be modified with the following:
static void PreSave(void) {
int x;
for(x=0;x<TotalSides;x++) {
int b;
for(b=0; b<65500; b++)
diskdata[x][b] ^= diskdatao[x][b];
}
}
static void PostSave (void) {
PreSave();
}
There was no error to fix in this example, but refactoring removed the V524 warning and simplified the code.
You can look at examples of errors detected by the V524 diagnostic. |