Skip to content

Commit 8b93b8a

Browse files
committed
add rewritten cstyleCast.md document [ci skip]
1 parent 365c47d commit 8b93b8a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

man/checkers/cstyleCast.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
```

0 commit comments

Comments
 (0)