cpp:S1242 false positive when overriding a function already declared pure virtual

I’m using SonarLint 5.3.0.36775 in JetBrains’ CLion and it keeps telling me to avoid shadowing inherited function sound() or to declare it virtual. Problem is that it’s already virtual, pure virtual to be exact, so I believe this is a false positive.

public:
    std::string who() const;
    virtual std::string sound() const = 0;

protected:
    Animal(std::string name, int weight) :
    m_name{name}, m_weight{weight} {}

private:
    std::string m_name;
    int m_weight;
};

class Sheep : public Animal{
public:
    using Animal::Animal;
    std::string sound() const override;
};

Hello @Thomas_Herondale,

Which compiler are you using with CLion?
I don’t reproduce it on my side so It might be a configuration issue instead of a rule implementation issue.

Thanks,

Hi @Abbas_Sabra!
I’m currently using the Visual Studio Compiler (version 16.0).

Thanks for your answer,

@Thomas_Herondale,

That was identified and fixed CPP-3289.

The problem is in finding the STL headers with Visual Studio Compilers. So you might face some false positives/negatives because of that. The fix should be available with SonarLint next release.

Thanks,

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.