[clang] [Clang] Restrict CWG1504 devirtualization to pointer arithmetic on record types (PR #209593)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 22 02:12:34 PDT 2026
================
@@ -2606,30 +2606,46 @@ CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
// objects accessed through array subscripts or pointer arithmetic with
// non-zero offsets, since the dynamic type must match the static type.
//
- // A single object is considered to be an array of one element, so p[0]
- // could still be a derived object, but p[N] for N != 0 cannot.
- const Expr *Inner = Base->IgnoreParenImpCasts();
- if (const auto *UO = dyn_cast<UnaryOperator>(Inner))
+ // Since a single object is treated as an array of one element for pointer
+ // arithmetic, p[0] could still designate a derived object, but p[N] for
+ // N != 0 cannot.
+
+ auto CheckPointerArithmetic = [&](const Expr *Ptr) -> CXXMethodDecl * {
+ Ptr = Ptr->IgnoreParenBaseCasts();
----------------
zwuis wrote:
Perhaps we can move some logic to `Expr::getBestDynamicClassTypeExpr`.
https://github.com/llvm/llvm-project/pull/209593
More information about the cfe-commits
mailing list