[clang-tools-extra] [clang-tidy] Add `bugprone-virtual-arithmetic` check (PR #91951)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 29 00:26:56 PDT 2024
================
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - bugprone-virtual-arithmetic
+
+bugprone-virtual-arithmetic
+===========================
+
+Warn if pointer arithmetic is performed on a class that declares a
+virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is
+different from its dynamic type is undefined behavior.
----------------
Discookie wrote:
indeed it could happen to any different static and dynamic types, but here it's better to be more specific for clarity, I think. The check only aims to find bugprone polymorphic objects anyways.
(`expr.add` in the standard specifically highlights polymorphic objects as well.)
https://github.com/llvm/llvm-project/pull/91951
More information about the cfe-commits
mailing list