Version used: SonarQube Enterprise Edition Version 8.9 (build 43852)
#bug:fp cpp:S1242
I have observed a bug with the following type of code in C++.
class ArgumentClass {
public:
...
};
class Interface {
public:
virtual void func(const ::std::vector<const ArgumentClass*>& args) const = 0;
virtual void func(const ::std::vector<ArgumentClass*>& args) const = 0;
};
class ImplClass : public virtual Interface {
public:
void func(const ::std::vector<const ArgumentClass*>& args) const override;
void func(const ::std::vector<ArgumentClass*>& args) const final;
};
class SubClass : public virtual ImplClass {
public:
void func(const ::std::vector<const ArgumentClass*>& args) const override;
};
I get the following warning:
Correct these functions so that no function in "SubClass::func" hides a function in "ImplClass::func"
Here’s the problem. I get an error message when I pass a vector of non-const objects to a function expecting const objects. So I have a function whose sole purpose is to convert the argument type to make the class useable with const and non-const arguments. That’s why I have both functions in the interface. The common implementation class (ImplClass) just converts the non-const objects to the const ones, and it’s marked final. In the SubClass, I have it override the behavior of just the one using the const objects.
I shouldn’t be getting this warning when the conflicting one is marked final. There is no ambiguity here, and there is no hiding. I think this warning should only kick in with regards to non-final functions.
This is a helpful warning in other circumstances, but not in this one. How can this issue get addressed?
Thank you.