[clang] [Clang] Prevent Null Pointer Dereference in in sema::isNormalAssignmentOperator() (PR #115880)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 01:26:24 PST 2024
================
@@ -482,8 +482,8 @@ static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
if (RetT->isLValueReferenceType()) {
ASTContext &Ctx = FD->getASTContext();
QualType LHST;
- auto *MD = dyn_cast<CXXMethodDecl>(FD);
- if (MD && MD->isCXXInstanceMember())
+ auto *MD = cast<CXXMethodDecl>(FD);
+ if (MD->isCXXInstanceMember())
LHST = Ctx.getLValueReferenceType(MD->getFunctionObjectParameterType());
else
LHST = MD->getParamDecl(0)->getType();
----------------
Sirraide wrote:
```suggestion
else
LHST = FD->getParamDecl(0)->getType();
```
I’m pretty sure this is a typo and is actually supposed to be this. I don’t think a `cast` instead of `dyn_cast` is right here because this is also a valid assignment operator, but it isn’t a `CXXMethodDecl`:
```c++
struct S {};
void operator|=(S, S) {}
```
@cor3ntin’s question as to whether this handles explicit object parameters correctly is also something we should investigate, but that seems like a separate issue.
https://github.com/llvm/llvm-project/pull/115880
More information about the cfe-commits
mailing list