# V1058. Nonsensical comparison of two different functions' addresses.

The analyzer has detected a suspicious comparison of two functions' addresses.

Consider the following example:

    namespace MyNamespace
    {
      int one() noexcept;
      int two() noexcept;
    }

    using namespace MyNamespace;

    void SomeFunction()
    {
      if (one != two)
      {
        // do something
      }
      ....
    }

In this code, the comparison will be always returning 'true' because 'one' and 'two' are names of functions with compatible signatures declared in the 'MyNamespace' namespace. The programmer must have intended to compare their return values but forgot to add parentheses to the functions' names:

    namespace MyNamespace
    {
      int one() noexcept;
      int two() noexcept;
    }

    using namespace MyNamespace;

    void SomeFunction()
    {
      if (one() != two())
      {
        // do something
      }
    }

Code like that could also be a result of poorly done refactoring. If the function contained a comparison of two local variables, which were later removed from the code while the condition itself was left intact, it could well result in comparing functions of the same names.

Example of code before refactoring:

    namespace MyNamespace
    {
      int one() noexcept;
      int two() noexcept;
    }

    using namespace MyNamespace;

    void SomeFunction(int one, int two)
    {
      if (one != two)
      {
        // do something
      }
    }

This diagnostic is classified as:

CWE-1025 CERT-EXP16-C