Skip to content

Commit 3501772

Browse files
ckandelergithub-actions[bot]
authored andcommitted
Automerge: [clang-tidy] Provide fix-its for casts to void* in google-readability-casting (#167655)
2 parents f88be09 + 915e9ad commit 3501772

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
248248
}
249249
break;
250250
}
251+
if (DestType->isVoidPointerType() && SourceType->isPointerType() &&
252+
!SourceType->getPointeeType()->isPointerType()) {
253+
ReplaceWithNamedCast("reinterpret_cast");
254+
return;
255+
}
256+
251257
[[fallthrough]];
252258
case clang::CK_IntegralCast:
253259
// Convert integral and no-op casts between builtin types and enums to

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ Changes in existing checks
426426

427427
- Improved :doc:`google-readability-casting
428428
<clang-tidy/checks/google/readability-casting>` check by adding fix-it
429-
notes for downcasts.
429+
notes for downcasts and casts to void pointer.
430430

431431
- Improved :doc:`google-readability-todo
432432
<clang-tidy/checks/google/readability-todo>` check to accept the new TODO

clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
108108
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast {{.*}}
109109
// CHECK-FIXES: Y &rB = static_cast<Y&>(*pX);
110110

111+
void *vp = (void *) pX;
112+
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}}; use reinterpret_cast
113+
// CHECK-FIXES: void *vp = reinterpret_cast<void *>(pX);
114+
111115
const char *pc3 = (const char*)cpv;
112116
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}; use static_cast [
113117
// CHECK-FIXES: const char *pc3 = static_cast<const char*>(cpv);

0 commit comments

Comments
 (0)