diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 9f7db6a9984f..021113999566 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -525,19 +525,21 @@ ExprResult Sema::DefaultFunctionArrayConversion(Expr *E, bool Diagnose) { if (DeclRefExpr* DR = dyn_cast(E)) { NamedDecl* D = DR->getFoundDecl(); FunctionDecl* Callee = isa(D) ? - cast(D)->getTemplatedDecl() : - cast(D); - // Overloaded operators end up here when called, but not when their address is taken, - // because they require the `&` in front of them - bool oper = Callee->isOverloadedOperator(); - if (!oper && Caller->hasAttr() && Callee->hasAttr()) { - Diag(E->getExprLoc(), diag::err_cheerp_wrong_function_addr) - << Callee << Callee->getAttr() - << Caller << Caller->getAttr(); - } else if (!oper && Caller->hasAttr() && Callee->hasAttr()) { - Diag(E->getExprLoc(), diag::err_cheerp_wrong_function_addr) - << Callee << Callee->getAttr() - << Caller << Caller->getAttr(); + cast(D)->getTemplatedDecl() : + isa(D)? cast(D) : nullptr; + if (Callee) { + // Overloaded operators end up here when called, but not when their address is taken, + // because they require the `&` in front of them + bool oper = Callee->isOverloadedOperator(); + if (!oper && Caller->hasAttr() && Callee->hasAttr()) { + Diag(E->getExprLoc(), diag::err_cheerp_wrong_function_addr) + << Callee << Callee->getAttr() + << Caller << Caller->getAttr(); + } else if (!oper && Caller->hasAttr() && Callee->hasAttr()) { + Diag(E->getExprLoc(), diag::err_cheerp_wrong_function_addr) + << Callee << Callee->getAttr() + << Caller << Caller->getAttr(); + } } } }