aboutsummaryrefslogtreecommitdiffstats
path: root/docs/checks/README-unneeded-cast.md
blob: cedcad6b944e05c799a6471e9d47da32112b7a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# unneeded-cast

Finds unneeded qobject_cast, static_cast and dynamic_casts.
Warns when you're casting to base or casting to the same type, which doesn't require
any explicit cast.

Also warns when you're using dynamic_cast for QObjects. qobject_cast is prefered.


#### Example

    Foo *a = ...;
    Foo *b = qobject_cast<Foo*>(a);


To shut the warnings about using qobject_cast over dynamic cast you can set:
`export CLAZY_EXTRA_OPTIONS="unneeded-cast-prefer-dynamic-cast-over-qobject"`

NOTE: This check has many false-positives. For example, you might cast to base
class to call a non-virtual method, or qobject_cast to itself to check if the
`QObject` destructor is currently being run.