@@ -2357,20 +2357,22 @@ Sema::DecomposeUnqualifiedId(const UnqualifiedId &Id,
23572357 }
23582358}
23592359
2360- static void emitEmptyLookupTypoDiagnostic(
2361- const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS,
2362- DeclarationName Typo, SourceLocation TypoLoc, ArrayRef<Expr *> Args,
2363- unsigned DiagnosticID, unsigned DiagnosticSuggestID) {
2360+ static void emitEmptyLookupTypoDiagnostic(const TypoCorrection &TC,
2361+ Sema &SemaRef, const CXXScopeSpec &SS,
2362+ DeclarationName Typo,
2363+ SourceRange TypoRange,
2364+ unsigned DiagnosticID,
2365+ unsigned DiagnosticSuggestID) {
23642366 DeclContext *Ctx =
23652367 SS.isEmpty() ? nullptr : SemaRef.computeDeclContext(SS, false);
23662368 if (!TC) {
23672369 // Emit a special diagnostic for failed member lookups.
23682370 // FIXME: computing the declaration context might fail here (?)
23692371 if (Ctx)
2370- SemaRef.Diag(TypoLoc , diag::err_no_member) << Typo << Ctx
2371- << SS.getRange() ;
2372+ SemaRef.Diag(TypoRange.getBegin() , diag::err_no_member)
2373+ << Typo << Ctx << TypoRange ;
23722374 else
2373- SemaRef.Diag(TypoLoc , DiagnosticID) << Typo;
2375+ SemaRef.Diag(TypoRange.getBegin() , DiagnosticID) << Typo << TypoRange ;
23742376 return;
23752377 }
23762378
@@ -2381,12 +2383,13 @@ static void emitEmptyLookupTypoDiagnostic(
23812383 ? diag::note_implicit_param_decl
23822384 : diag::note_previous_decl;
23832385 if (!Ctx)
2384- SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo,
2385- SemaRef.PDiag(NoteID));
2386+ SemaRef.diagnoseTypo(
2387+ TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo << TypoRange,
2388+ SemaRef.PDiag(NoteID));
23862389 else
2387- SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
2388- << Typo << Ctx << DroppedSpecifier
2389- << SS.getRange() ,
2390+ SemaRef.diagnoseTypo(TC,
2391+ SemaRef.PDiag(diag::err_no_member_suggest)
2392+ << Typo << Ctx << DroppedSpecifier << TypoRange ,
23902393 SemaRef.PDiag(NoteID));
23912394}
23922395
@@ -2455,6 +2458,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
24552458 ArrayRef<Expr *> Args, DeclContext *LookupCtx,
24562459 TypoExpr **Out) {
24572460 DeclarationName Name = R.getLookupName();
2461+ SourceRange NameRange = R.getLookupNameInfo().getSourceRange();
24582462
24592463 unsigned diagnostic = diag::err_undeclared_var_use;
24602464 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
@@ -2512,13 +2516,12 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
25122516 // We didn't find anything, so try to correct for a typo.
25132517 TypoCorrection Corrected;
25142518 if (S && Out) {
2515- SourceLocation TypoLoc = R.getNameLoc();
25162519 assert(!ExplicitTemplateArgs &&
25172520 "Diagnosing an empty lookup with explicit template args!");
25182521 *Out = CorrectTypoDelayed(
25192522 R.getLookupNameInfo(), R.getLookupKind(), S, &SS, CCC,
25202523 [=](const TypoCorrection &TC) {
2521- emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args ,
2524+ emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, NameRange ,
25222525 diagnostic, diagnostic_suggest);
25232526 },
25242527 nullptr, CTK_ErrorRecovery, LookupCtx);
@@ -2597,12 +2600,13 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
25972600 ? diag::note_implicit_param_decl
25982601 : diag::note_previous_decl;
25992602 if (SS.isEmpty())
2600- diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name,
2603+ diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name << NameRange ,
26012604 PDiag(NoteID), AcceptableWithRecovery);
26022605 else
2603- diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
2604- << Name << computeDeclContext(SS, false)
2605- << DroppedSpecifier << SS.getRange(),
2606+ diagnoseTypo(Corrected,
2607+ PDiag(diag::err_no_member_suggest)
2608+ << Name << computeDeclContext(SS, false)
2609+ << DroppedSpecifier << NameRange,
26062610 PDiag(NoteID), AcceptableWithRecovery);
26072611
26082612 // Tell the callee whether to try to recover.
@@ -2615,13 +2619,12 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
26152619 // FIXME: computing the declaration context might fail here (?)
26162620 if (!SS.isEmpty()) {
26172621 Diag(R.getNameLoc(), diag::err_no_member)
2618- << Name << computeDeclContext(SS, false)
2619- << SS.getRange();
2622+ << Name << computeDeclContext(SS, false) << NameRange;
26202623 return true;
26212624 }
26222625
26232626 // Give up, we can't recover.
2624- Diag(R.getNameLoc(), diagnostic) << Name;
2627+ Diag(R.getNameLoc(), diagnostic) << Name << NameRange ;
26252628 return true;
26262629}
26272630
0 commit comments