mardi 6 juillet 2021

How to make cppcheck show error on calls to a virtual function in constructor

In the list of cppcheck rules there is

<error id="virtualCallInConstructor" severity="style" msg="Virtual function 'f' is called from constructor '' at line

  1. Dynamic binding is not used." verbose="Virtual function 'f' is called from constructor '' at line 1. Dynamic binding is not used."/>

I've written a call to a virtual functions in several classes in my solution and run cppcheck o them, but it didn't show this error.

I've used GUI and also run cppcheck from command line with --enable=style and --enable=all

How can I make cppcheck to show this issue? I'm using latest cppcheck

Another dummy code I've run cppcheck on

class A
{
public:
    A() { }
    virtual void fin() = 0;
};

class B : public A
{
public:
    B() { fin(); }
    void fin() { std::cout << "l"; }
};

class C : public B
{
public:
    C() {}
    void fin() { std::cout << "c"; }
};

Aucun commentaire:

Enregistrer un commentaire