[clang] [clang-tidy]Add new check bugprone-casting-through-void (PR #69465)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 09:06:53 PDT 2023
================
@@ -0,0 +1,11 @@
+.. title:: clang-tidy - bugprone-casting-through-void
+
+bugprone-casting-through-void
+=============================
+
+A check detects usage of ``static_cast`` pointer to the other pointer throght
+``static_cast`` to ``void *`` in C++ code.
+
+Use of these casts can violate type safety and cause the program to access a
----------------
PiotrZSL wrote:
Maybe something like this:
Two-step type conversions via void* are discouraged for several reasons. Firstly, they obscure code and impede its understandability, complicating maintenance. Additionally, these conversions bypass valuable compiler support, erasing warnings related to pointer alignment and potentially leading to undefined behavior. In scenarios involving multiple inheritance, ambiguity and unexpected outcomes can arise due to the loss of type information, posing runtime issues. In summary, avoiding two-step type conversions through void* ensures clearer code, maintains essential compiler warnings, and prevents ambiguity and potential runtime errors, particularly in complex inheritance scenarios.
https://github.com/llvm/llvm-project/pull/69465
More information about the cfe-commits
mailing list