Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
}
break;
}
if (DestType->isVoidPointerType() && SourceType->isPointerType() &&
!SourceType->getPointeeType()->isPointerType()) {
ReplaceWithNamedCast("reinterpret_cast");
return;
}

[[fallthrough]];
case clang::CK_IntegralCast:
// Convert integral and no-op casts between builtin types and enums to
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Changes in existing checks

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

- Improved :doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals
<clang-tidy/checks/llvm/prefer-isa-or-dyn-cast-in-conditionals>` check:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast {{.*}}
// CHECK-FIXES: Y &rB = static_cast<Y&>(*pX);

void *vp = (void *) pX;
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}}; use reinterpret_cast
// CHECK-FIXES: void *vp = reinterpret_cast<void *>(pX);

const char *pc3 = (const char*)cpv;
// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}; use static_cast [
// CHECK-FIXES: const char *pc3 = static_cast<const char*>(cpv);
Expand Down
Loading