diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b4a7ceaa1bb1..3c9981ca70d6 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -519,8 +519,9 @@ ExprResult Sema::DefaultFunctionArrayConversion(Expr *E, bool Diagnose) { return ExprError(); // CHEERP: Cannot take function addresses from genericjs to asmjs and vice versa - if (CurScope && CurScope->getFnParent() && CurScope->getFnParent()->getEntity()) { - if (FunctionDecl* Caller = dyn_cast(CurScope->getFnParent()->getEntity())) { + // except in decltype context + if (ExprEvalContexts.back().ExprContext != ExpressionEvaluationContextRecord::EK_Decltype) { + if (FunctionDecl* Caller = getCurFunctionDecl()) { if (DeclRefExpr* DR = dyn_cast(E)) { NamedDecl* D = DR->getFoundDecl(); FunctionDecl* Callee = isa(D) ? @@ -14472,9 +14473,10 @@ QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) { } } // CHEERP: Cannot take function addresses from genericjs to asmjs and vice versa + // except in decltype context else if (op->getType()->isFunctionType()) { - if (CurScope && CurScope->getFnParent()) { - if (FunctionDecl* Caller = dyn_cast_or_null(CurScope->getFnParent()->getEntity())) { + if (ExprEvalContexts.back().ExprContext != ExpressionEvaluationContextRecord::EK_Decltype) { + if (FunctionDecl* Caller = getCurFunctionDecl()) { if (DeclRefExpr* DR = dyn_cast(op)) { if (FunctionDecl* Callee = dyn_cast(DR->getFoundDecl())) { if (Caller->hasAttr() && Callee->hasAttr()) {