-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[clang-tidy] Rename google-readability-casting to modernize-avoid-c-style-cast
#171058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b0e4d73
2b6af30
258997e
5eff8ef
b2dca18
451b8eb
d97d9b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,10 @@ | |
| google-readability-casting | ||
| ========================== | ||
|
|
||
| The `google-readability-casting` check is an alias, please see | ||
| :doc:`modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast>` | ||
| for more information. | ||
|
|
||
| Finds usages of C-style casts. | ||
|
|
||
| https://google.github.io/styleguide/cppguide.html#Casting | ||
|
|
||
| Corresponding cpplint.py check name: `readability/casting`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
|
|
||
| This check is similar to ``-Wold-style-cast``, but it suggests automated fixes | ||
| in some cases. The reported locations should not be different from the | ||
| ones generated by ``-Wold-style-cast``. | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||
| .. title:: clang-tidy - modernize-avoid-c-style-cast | ||||||||
|
|
||||||||
| modernize-avoid-c-style-cast | ||||||||
| ============================ | ||||||||
|
|
||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Forgot the initial line |
||||||||
|
|
||||||||
| C-style casts can perform a variety of different conversions (``const_cast``, | ||||||||
| ``static_cast``, ``reinterpret_cast``, or a combination). This makes them | ||||||||
| dangerous as the intent is not clear, and they can silently perform unsafe | ||||||||
| conversions between incompatible types. | ||||||||
zeyi2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| This check is similar to `-Wold-style-cast`, but it suggests automated fixes | ||||||||
| in some cases. The reported locations should not be different from the ones | ||||||||
| generated by `-Wold-style-cast`. | ||||||||
|
|
||||||||
| Examples | ||||||||
| -------- | ||||||||
|
|
||||||||
| .. code-block:: c++ | ||||||||
|
|
||||||||
| class A { | ||||||||
| public: | ||||||||
| std::string v; | ||||||||
| }; | ||||||||
|
|
||||||||
| A a; | ||||||||
| double *num = (double*)(&a); // Compiles! Hides danger | ||||||||
| // num = static_cast<double*>(&a); // Won't compile (good!) | ||||||||
| num = reinterpret_cast<double*>(&a); // Compiles, danger is explicit | ||||||||
|
|
||||||||
|
|
||||||||
| References | ||||||||
| ---------- | ||||||||
|
|
||||||||
| Corresponding cpplint.py check name: `readability/casting`. | ||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // RUN: %check_clang_tidy %s modernize-avoid-c-style-cast %t -- -- -x c | ||
| // The testing script always adds .cpp extension to the input file name, so we | ||
| // need to run clang-tidy directly in order to verify handling of .c files: | ||
| // RUN: clang-tidy --checks=-*,modernize-avoid-c-style-cast %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:' | ||
| // RUN: cp %s %t.main_file.cpp | ||
| // RUN: clang-tidy --checks=-*,modernize-avoid-c-style-cast -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:' | ||
|
|
||
| #ifdef TEST_INCLUDE | ||
|
|
||
| #undef TEST_INCLUDE | ||
| #include "avoid-c-style-cast.c" | ||
|
|
||
| #else | ||
|
|
||
| void f(const char *cpc) { | ||
| const char *cpc2 = (const char*)cpc; | ||
| // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [modernize-avoid-c-style-cast] | ||
| // CHECK-FIXES: const char *cpc2 = cpc; | ||
| char *pc = (char*)cpc; | ||
| typedef const char *Typedef1; | ||
| (Typedef1)cpc; | ||
| } | ||
|
|
||
| #endif |
Uh oh!
There was an error while loading. Please reload this page.