File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ # cstyleCast
3+
4+ ** Message** : C-style pointer casting<br />
5+ ** Category** : Modernization<br />
6+ ** Severity** : Style<br />
7+ ** Language** : C++, not applicable for C code
8+
9+ ## Description
10+
11+ Many developers feel that it's best practice to replace C casts with C++ casts.
12+
13+ This checker is about C casts that converts to/from a pointer or reference.
14+
15+ Potential safety issues are covered by other warnings so this ID ` cstyleCast ` is primarily about writing warnings for casts that are safe.
16+
17+ ## How to fix
18+
19+ You can use C++ casts such as ` static_cast ` to fix these warnings.
20+
21+ Before:
22+ ``` cpp
23+ struct Base {};
24+ struct Derived : public Base {};
25+ void foo(Base* base) {
26+ Base * p = (Base* )derived; // <- cstyleCast, safe cast from derived object to base object
27+ }
28+ ```
29+
30+ After:
31+ ```cpp
32+ struct Base{};
33+ struct Derived: public Base {};
34+ void foo(Base* base) {
35+ Derived *p = static_cast<Derived*>(base);
36+ }
37+ ```
You can’t perform that action at this time.
0 commit comments