@@ -2376,20 +2376,22 @@ Sema::DecomposeUnqualifiedId(const UnqualifiedId &Id,
23762376 }
23772377}
23782378
2379- static void emitEmptyLookupTypoDiagnostic(
2380- const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS,
2381- DeclarationName Typo, SourceLocation TypoLoc, ArrayRef<Expr *> Args,
2382- unsigned DiagnosticID, unsigned DiagnosticSuggestID) {
2379+ static void emitEmptyLookupTypoDiagnostic(const TypoCorrection &TC,
2380+ Sema &SemaRef, const CXXScopeSpec &SS,
2381+ DeclarationName Typo,
2382+ SourceRange TypoRange,
2383+ unsigned DiagnosticID,
2384+ unsigned DiagnosticSuggestID) {
23832385 DeclContext *Ctx =
23842386 SS.isEmpty() ? nullptr : SemaRef.computeDeclContext(SS, false);
23852387 if (!TC) {
23862388 // Emit a special diagnostic for failed member lookups.
23872389 // FIXME: computing the declaration context might fail here (?)
23882390 if (Ctx)
2389- SemaRef.Diag(TypoLoc , diag::err_no_member) << Typo << Ctx
2390- << SS.getRange() ;
2391+ SemaRef.Diag(TypoRange.getBegin() , diag::err_no_member)
2392+ << Typo << Ctx << TypoRange ;
23912393 else
2392- SemaRef.Diag(TypoLoc , DiagnosticID) << Typo;
2394+ SemaRef.Diag(TypoRange.getBegin() , DiagnosticID) << Typo << TypoRange ;
23932395 return;
23942396 }
23952397
@@ -2400,12 +2402,13 @@ static void emitEmptyLookupTypoDiagnostic(
24002402 ? diag::note_implicit_param_decl
24012403 : diag::note_previous_decl;
24022404 if (!Ctx)
2403- SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo,
2404- SemaRef.PDiag(NoteID));
2405+ SemaRef.diagnoseTypo(
2406+ TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo << TypoRange,
2407+ SemaRef.PDiag(NoteID));
24052408 else
2406- SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
2407- << Typo << Ctx << DroppedSpecifier
2408- << SS.getRange() ,
2409+ SemaRef.diagnoseTypo(TC,
2410+ SemaRef.PDiag(diag::err_no_member_suggest)
2411+ << Typo << Ctx << DroppedSpecifier << TypoRange ,
24092412 SemaRef.PDiag(NoteID));
24102413}
24112414
@@ -2474,6 +2477,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
24742477 ArrayRef<Expr *> Args, DeclContext *LookupCtx,
24752478 TypoExpr **Out) {
24762479 DeclarationName Name = R.getLookupName();
2480+ SourceRange NameRange = R.getLookupNameInfo().getSourceRange();
24772481
24782482 unsigned diagnostic = diag::err_undeclared_var_use;
24792483 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
@@ -2531,13 +2535,12 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
25312535 // We didn't find anything, so try to correct for a typo.
25322536 TypoCorrection Corrected;
25332537 if (S && Out) {
2534- SourceLocation TypoLoc = R.getNameLoc();
25352538 assert(!ExplicitTemplateArgs &&
25362539 "Diagnosing an empty lookup with explicit template args!");
25372540 *Out = CorrectTypoDelayed(
25382541 R.getLookupNameInfo(), R.getLookupKind(), S, &SS, CCC,
25392542 [=](const TypoCorrection &TC) {
2540- emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args ,
2543+ emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, NameRange ,
25412544 diagnostic, diagnostic_suggest);
25422545 },
25432546 nullptr, CTK_ErrorRecovery, LookupCtx);
@@ -2616,12 +2619,13 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
26162619 ? diag::note_implicit_param_decl
26172620 : diag::note_previous_decl;
26182621 if (SS.isEmpty())
2619- diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name,
2622+ diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name << NameRange ,
26202623 PDiag(NoteID), AcceptableWithRecovery);
26212624 else
2622- diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
2623- << Name << computeDeclContext(SS, false)
2624- << DroppedSpecifier << SS.getRange(),
2625+ diagnoseTypo(Corrected,
2626+ PDiag(diag::err_no_member_suggest)
2627+ << Name << computeDeclContext(SS, false)
2628+ << DroppedSpecifier << NameRange,
26252629 PDiag(NoteID), AcceptableWithRecovery);
26262630
26272631 // Tell the callee whether to try to recover.
@@ -2634,13 +2638,12 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
26342638 // FIXME: computing the declaration context might fail here (?)
26352639 if (!SS.isEmpty()) {
26362640 Diag(R.getNameLoc(), diag::err_no_member)
2637- << Name << computeDeclContext(SS, false)
2638- << SS.getRange();
2641+ << Name << computeDeclContext(SS, false) << NameRange;
26392642 return true;
26402643 }
26412644
26422645 // Give up, we can't recover.
2643- Diag(R.getNameLoc(), diagnostic) << Name;
2646+ Diag(R.getNameLoc(), diagnostic) << Name << NameRange ;
26442647 return true;
26452648}
26462649
0 commit comments