[clang] [clang-tidy] [dataflow] Cache reference accessors for `bugprone-unchecked-optional-access` (PR #128437)
Jan Voung via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 25 07:29:42 PST 2025
================
@@ -580,6 +580,26 @@ void handleConstMemberCall(const CallExpr *CE,
return;
}
+ // Cache if the const method returns a reference
+ if (RecordLoc != nullptr && CE->isGLValue()) {
+ const FunctionDecl *DirectCallee = CE->getDirectCallee();
+ if (DirectCallee == nullptr)
+ return;
+
+ bool isReference =
+ DirectCallee->getReturnType().getTypePtr()->isReferenceType();
+ if (isReference) {
----------------
jvoung wrote:
Yes, I think it wouldn't be needed.
Otherwise, `DirectCallee->getReturnType()->isReferenceType()` is a bit shorter (the operator-> will do getTypePtr)
https://github.com/llvm/llvm-project/pull/128437
More information about the cfe-commits
mailing list