1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
# copyable-polymorphic
Finds polymorphic classes that are copyable.
Classes with virtual methods are usually handled by pointer, as passing
then by value would allow up-casting to the base-class and slicing off the vtable.
Example:
```
struct Base {
virtual int getNumber() const { return 41; }
};
struct Derived : public Base {
int getNumber() const override { return 42; }
};
void printNumber(Base b)
{
qDebug() << b.getNumber(); // Always prints 41!
}
(...)
Derived d;
printNumber(d);
```
To fix these warnings use `Q_DISABLE_COPY` or delete the copy-ctor yourself.
This check supports a fixit, however you'll need to set the env var
CLAZY_ACCESSSPECIFIER_NON_QOBJECT=1. It's opt-in since it involves a bit of cpu
overhead and is also responsible for bug #431186
|