@@ -4377,120 +4377,52 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
4377
4377
4378
4378
// If the user is trying to apply -> or . to a function name, it's probably
4379
4379
// because they forgot parentheses to call that function.
4380
- bool TryCall = false ;
4381
- bool Overloaded = false ;
4382
- UnresolvedSet<8 > AllOverloads;
4383
- if (const OverloadExpr *Overloads = dyn_cast<OverloadExpr>(BaseExpr.get ())) {
4384
- AllOverloads.append (Overloads->decls_begin (), Overloads->decls_end ());
4385
- TryCall = true ;
4386
- Overloaded = true ;
4387
- } else if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(BaseExpr.get ())) {
4388
- if (FunctionDecl* Fun = dyn_cast<FunctionDecl>(DeclRef->getDecl ())) {
4389
- AllOverloads.addDecl (Fun);
4390
- TryCall = true ;
4391
- }
4392
- }
4393
-
4394
- if (TryCall) {
4395
- // Plunder the overload set for something that would make the member
4396
- // expression valid.
4397
- UnresolvedSet<4 > ViableOverloads;
4398
- bool HasViableZeroArgOverload = false ;
4399
- for (OverloadExpr::decls_iterator it = AllOverloads.begin (),
4400
- DeclsEnd = AllOverloads.end (); it != DeclsEnd; ++it) {
4401
- // Our overload set may include TemplateDecls, which we'll ignore for the
4402
- // purposes of determining whether we can issue a '()' fixit.
4403
- if (const FunctionDecl *OverloadDecl = dyn_cast<FunctionDecl>(*it)) {
4404
- QualType ResultTy = OverloadDecl->getResultType ();
4405
- if ((!IsArrow && ResultTy->isRecordType ()) ||
4406
- (IsArrow && ResultTy->isPointerType () &&
4407
- ResultTy->getPointeeType ()->isRecordType ())) {
4408
- ViableOverloads.addDecl (*it);
4409
- if (OverloadDecl->getMinRequiredArguments () == 0 ) {
4410
- HasViableZeroArgOverload = true ;
4411
- }
4412
- }
4413
- }
4414
- }
4415
-
4416
- if (!HasViableZeroArgOverload || ViableOverloads.size () != 1 ) {
4380
+ QualType ZeroArgCallTy;
4381
+ UnresolvedSet<4 > Overloads;
4382
+ if (isExprCallable (*BaseExpr.get (), ZeroArgCallTy, Overloads)) {
4383
+ if (ZeroArgCallTy.isNull ()) {
4417
4384
Diag (BaseExpr.get ()->getExprLoc (), diag::err_member_reference_needs_call)
4418
- << (AllOverloads.size () > 1 ) << 0
4419
- << BaseExpr.get ()->getSourceRange ();
4420
- int ViableOverloadCount = ViableOverloads.size ();
4421
- int I;
4422
- for (I = 0 ; I < ViableOverloadCount; ++I) {
4423
- // FIXME: Magic number for max shown overloads stolen from
4424
- // OverloadCandidateSet::NoteCandidates.
4425
- if (I >= 4 && Diags.getShowOverloads () == Diagnostic::Ovl_Best) {
4426
- break ;
4427
- }
4428
- Diag (ViableOverloads[I].getDecl ()->getSourceRange ().getBegin (),
4429
- diag::note_member_ref_possible_intended_overload);
4430
- }
4431
- if (I != ViableOverloadCount) {
4432
- Diag (BaseExpr.get ()->getExprLoc (), diag::note_ovl_too_many_candidates)
4433
- << int (ViableOverloadCount - I);
4385
+ << (Overloads.size () > 1 ) << 0 << BaseExpr.get ()->getSourceRange ();
4386
+ UnresolvedSet<2 > PlausibleOverloads;
4387
+ for (OverloadExpr::decls_iterator It = Overloads.begin (),
4388
+ DeclsEnd = Overloads.end (); It != DeclsEnd; ++It) {
4389
+ const FunctionDecl *OverloadDecl = cast<FunctionDecl>(*It);
4390
+ QualType OverloadResultTy = OverloadDecl->getResultType ();
4391
+ if ((!IsArrow && OverloadResultTy->isRecordType ()) ||
4392
+ (IsArrow && OverloadResultTy->isPointerType () &&
4393
+ OverloadResultTy->getPointeeType ()->isRecordType ()))
4394
+ PlausibleOverloads.addDecl (It.getDecl ());
4434
4395
}
4396
+ NoteOverloads (PlausibleOverloads, BaseExpr.get ()->getExprLoc ());
4435
4397
return ExprError ();
4436
4398
}
4437
- } else {
4438
- // We don't have an expression that's convenient to get a Decl from, but we
4439
- // can at least check if the type is "function of 0 arguments which returns
4440
- // an acceptable type".
4441
- const FunctionType *Fun = NULL ;
4442
- if (const PointerType *Ptr = BaseType->getAs <PointerType>()) {
4443
- if ((Fun = Ptr->getPointeeType ()->getAs <FunctionType>())) {
4444
- TryCall = true ;
4445
- }
4446
- } else if ((Fun = BaseType->getAs <FunctionType>())) {
4447
- TryCall = true ;
4448
- } else if (BaseType == Context.BoundMemberTy ) {
4449
- // Look for the bound-member type. If it's still overloaded,
4450
- // give up, although we probably should have fallen into the
4451
- // OverloadExpr case above if we actually have an overloaded
4452
- // bound member.
4453
- QualType fnType = Expr::findBoundMemberType (BaseExpr.get ());
4454
- if (!fnType.isNull ()) {
4455
- TryCall = true ;
4456
- Fun = fnType->castAs <FunctionType>();
4457
- }
4458
- }
4459
-
4460
- if (TryCall) {
4461
- if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(Fun)) {
4462
- if (FPT->getNumArgs () == 0 ) {
4463
- QualType ResultTy = Fun->getResultType ();
4464
- TryCall = (!IsArrow && ResultTy->isRecordType ()) ||
4465
- (IsArrow && ResultTy->isPointerType () &&
4466
- ResultTy->getPointeeType ()->isRecordType ());
4467
- }
4468
- }
4399
+ if ((!IsArrow && ZeroArgCallTy->isRecordType ()) ||
4400
+ (IsArrow && ZeroArgCallTy->isPointerType () &&
4401
+ ZeroArgCallTy->getPointeeType ()->isRecordType ())) {
4402
+ // At this point, we know BaseExpr looks like it's potentially callable
4403
+ // with 0 arguments, and that it returns something of a reasonable type,
4404
+ // so we can emit a fixit and carry on pretending that BaseExpr was
4405
+ // actually a CallExpr.
4406
+ SourceLocation ParenInsertionLoc =
4407
+ PP.getLocForEndOfToken (BaseExpr.get ()->getLocEnd ());
4408
+ Diag (BaseExpr.get ()->getExprLoc (), diag::err_member_reference_needs_call)
4409
+ << (Overloads.size () > 1 ) << 1 << BaseExpr.get ()->getSourceRange ()
4410
+ << FixItHint::CreateInsertion (ParenInsertionLoc, " ()" );
4411
+ // FIXME: Try this before emitting the fixit, and suppress diagnostics
4412
+ // while doing so.
4413
+ ExprResult NewBase =
4414
+ ActOnCallExpr (0 , BaseExpr.take (), ParenInsertionLoc,
4415
+ MultiExprArg (*this , 0 , 0 ),
4416
+ ParenInsertionLoc.getFileLocWithOffset (1 ));
4417
+ if (NewBase.isInvalid ())
4418
+ return ExprError ();
4419
+ BaseExpr = NewBase;
4420
+ BaseExpr = DefaultFunctionArrayConversion (BaseExpr.take ());
4421
+ return LookupMemberExpr (R, BaseExpr, IsArrow, OpLoc, SS,
4422
+ ObjCImpDecl, HasTemplateArgs);
4469
4423
}
4470
4424
}
4471
4425
4472
- if (TryCall) {
4473
- // At this point, we know BaseExpr looks like it's potentially callable with
4474
- // 0 arguments, and that it returns something of a reasonable type, so we
4475
- // can emit a fixit and carry on pretending that BaseExpr was actually a
4476
- // CallExpr.
4477
- SourceLocation ParenInsertionLoc =
4478
- PP.getLocForEndOfToken (BaseExpr.get ()->getLocEnd ());
4479
- Diag (BaseExpr.get ()->getExprLoc (), diag::err_member_reference_needs_call)
4480
- << int (Overloaded) << 1
4481
- << BaseExpr.get ()->getSourceRange ()
4482
- << FixItHint::CreateInsertion (ParenInsertionLoc, " ()" );
4483
- ExprResult NewBase = ActOnCallExpr (0 , BaseExpr.take (), ParenInsertionLoc,
4484
- MultiExprArg (*this , 0 , 0 ),
4485
- ParenInsertionLoc);
4486
- if (NewBase.isInvalid ())
4487
- return ExprError ();
4488
- BaseExpr = NewBase;
4489
- BaseExpr = DefaultFunctionArrayConversion (BaseExpr.take ());
4490
- return LookupMemberExpr (R, BaseExpr, IsArrow, OpLoc, SS,
4491
- ObjCImpDecl, HasTemplateArgs);
4492
- }
4493
-
4494
4426
Diag (MemberLoc, diag::err_typecheck_member_reference_struct_union)
4495
4427
<< BaseType << BaseExpr.get ()->getSourceRange ();
4496
4428
0 commit comments