@@ -5827,96 +5827,13 @@ class ConceptInfo {
58275827// We accept some lossiness (like dropping parameters).
58285828// We only try to handle common expressions on the LHS of MemberExpr.
58295829QualType getApproximateType (const Expr *E, HeuristicResolver &Resolver) {
5830- if (E->getType ().isNull ())
5831- return QualType ();
5832- // Don't drop implicit cast if it's an array decay.
5833- if (auto *ICE = dyn_cast<ImplicitCastExpr>(E);
5834- !ICE || ICE->getCastKind () != CK_ArrayToPointerDecay)
5835- E = E->IgnoreParenImpCasts ();
5836- QualType Unresolved = E->getType ();
5837- // Resolve DependentNameType
5838- if (const auto *DNT = Unresolved->getAs <DependentNameType>()) {
5839- if (auto Decls = Resolver.resolveDependentNameType (DNT);
5840- Decls.size () == 1 ) {
5841- if (const auto *TD = dyn_cast<TypeDecl>(Decls[0 ]))
5842- return TD->getASTContext ().getTypeDeclType (TD);
5843- }
5844- }
5845- // We only resolve DependentTy, or undeduced autos (including auto* etc).
5846- if (!Unresolved->isSpecificBuiltinType (BuiltinType::Dependent)) {
5847- AutoType *Auto = Unresolved->getContainedAutoType ();
5848- if (!Auto || !Auto->isUndeducedAutoType ())
5849- return Unresolved;
5850- }
5851- // A call: approximate-resolve callee to a function type, get its return type
5852- if (const CallExpr *CE = llvm::dyn_cast<CallExpr>(E)) {
5853- QualType Callee = getApproximateType (CE->getCallee (), Resolver);
5854- if (Callee.isNull () ||
5855- Callee->isSpecificPlaceholderType (BuiltinType::BoundMember))
5856- Callee = Expr::findBoundMemberType (CE->getCallee ());
5857- if (Callee.isNull ())
5858- return Unresolved;
5859-
5860- if (const auto *FnTypePtr = Callee->getAs <PointerType>()) {
5861- Callee = FnTypePtr->getPointeeType ();
5862- } else if (const auto *BPT = Callee->getAs <BlockPointerType>()) {
5863- Callee = BPT->getPointeeType ();
5864- }
5865- if (const FunctionType *FnType = Callee->getAs <FunctionType>())
5866- return FnType->getReturnType ().getNonReferenceType ();
5867-
5868- // Unresolved call: try to guess the return type.
5869- if (const auto *OE = llvm::dyn_cast<OverloadExpr>(CE->getCallee ())) {
5870- // If all candidates have the same approximate return type, use it.
5871- // Discard references and const to allow more to be "the same".
5872- // (In particular, if there's one candidate + ADL, resolve it).
5873- const Type *Common = nullptr ;
5874- for (const auto *D : OE->decls ()) {
5875- QualType ReturnType;
5876- if (const auto *FD = llvm::dyn_cast<FunctionDecl>(D))
5877- ReturnType = FD->getReturnType ();
5878- else if (const auto *FTD = llvm::dyn_cast<FunctionTemplateDecl>(D))
5879- ReturnType = FTD->getTemplatedDecl ()->getReturnType ();
5880- if (ReturnType.isNull ())
5881- continue ;
5882- const Type *Candidate =
5883- ReturnType.getNonReferenceType ().getCanonicalType ().getTypePtr ();
5884- if (Common && Common != Candidate)
5885- return Unresolved; // Multiple candidates.
5886- Common = Candidate;
5887- }
5888- if (Common != nullptr )
5889- return QualType (Common, 0 );
5890- }
5891- }
5892- // A dependent member: resolve using HeuristicResolver.
5893- if (const auto *CDSME = llvm::dyn_cast<CXXDependentScopeMemberExpr>(E)) {
5894- for (const auto *Member : Resolver.resolveMemberExpr (CDSME)) {
5895- if (const auto *VD = dyn_cast<ValueDecl>(Member)) {
5896- return VD->getType ().getNonReferenceType ();
5897- }
5898- }
5899- }
5900- // A reference to an `auto` variable: approximate-resolve its initializer.
5901- if (const auto *DRE = llvm::dyn_cast<DeclRefExpr>(E)) {
5902- if (const auto *VD = llvm::dyn_cast<VarDecl>(DRE->getDecl ())) {
5903- if (VD->hasInit ())
5904- return getApproximateType (VD->getInit (), Resolver);
5905- }
5906- }
5907- if (const auto *UO = llvm::dyn_cast<UnaryOperator>(E)) {
5908- if (UO->getOpcode () == UnaryOperatorKind::UO_Deref) {
5909- // We recurse into the subexpression because it could be of dependent
5910- // type.
5911- if (auto Pointee =
5912- getApproximateType (UO->getSubExpr (), Resolver)->getPointeeType ();
5913- !Pointee.isNull ())
5914- return Pointee;
5915- // Our caller expects a non-null result, even though the SubType is
5916- // supposed to have a pointee. Fall through to Unresolved anyway.
5917- }
5918- }
5919- return Unresolved;
5830+ QualType Result = Resolver.resolveExprToType (E);
5831+ if (Result.isNull ())
5832+ return Result;
5833+ Result = Resolver.simplifyType (Result.getNonReferenceType (), E, false );
5834+ if (Result.isNull ())
5835+ return Result;
5836+ return Result.getNonReferenceType ();
59205837}
59215838
59225839// If \p Base is ParenListExpr, assume a chain of comma operators and pick the
0 commit comments