File: README-copyable-polymorphic.md

package info (click to toggle)
clazy 1.17-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 5,248 kB
  • sloc: cpp: 23,552; python: 1,450; xml: 450; sh: 237; makefile: 46
file content (32 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (4)
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