@@ -2351,20 +2351,22 @@ Sema::DecomposeUnqualifiedId(const UnqualifiedId &Id,
23512351 }
23522352}
23532353
2354- static void emitEmptyLookupTypoDiagnostic(
2355- const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS,
2356- DeclarationName Typo, SourceLocation TypoLoc, ArrayRef<Expr *> Args,
2357- unsigned DiagnosticID, unsigned DiagnosticSuggestID) {
2354+ static void emitEmptyLookupTypoDiagnostic(const TypoCorrection &TC,
2355+ Sema &SemaRef, const CXXScopeSpec &SS,
2356+ DeclarationName Typo,
2357+ SourceRange TypoRange,
2358+ unsigned DiagnosticID,
2359+ unsigned DiagnosticSuggestID) {
23582360 DeclContext *Ctx =
23592361 SS.isEmpty() ? nullptr : SemaRef.computeDeclContext(SS, false);
23602362 if (!TC) {
23612363 // Emit a special diagnostic for failed member lookups.
23622364 // FIXME: computing the declaration context might fail here (?)
23632365 if (Ctx)
2364- SemaRef.Diag(TypoLoc , diag::err_no_member) << Typo << Ctx
2365- << SS.getRange() ;
2366+ SemaRef.Diag(TypoRange.getBegin() , diag::err_no_member)
2367+ << Typo << Ctx << TypoRange ;
23662368 else
2367- SemaRef.Diag(TypoLoc , DiagnosticID) << Typo;
2369+ SemaRef.Diag(TypoRange.getBegin() , DiagnosticID) << Typo << TypoRange ;
23682370 return;
23692371 }
23702372
@@ -2375,12 +2377,13 @@ static void emitEmptyLookupTypoDiagnostic(
23752377 ? diag::note_implicit_param_decl
23762378 : diag::note_previous_decl;
23772379 if (!Ctx)
2378- SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo,
2379- SemaRef.PDiag(NoteID));
2380+ SemaRef.diagnoseTypo(
2381+ TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo << TypoRange,
2382+ SemaRef.PDiag(NoteID));
23802383 else
2381- SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest)
2382- << Typo << Ctx << DroppedSpecifier
2383- << SS.getRange() ,
2384+ SemaRef.diagnoseTypo(TC,
2385+ SemaRef.PDiag(diag::err_no_member_suggest)
2386+ << Typo << Ctx << DroppedSpecifier << TypoRange ,
23842387 SemaRef.PDiag(NoteID));
23852388}
23862389
@@ -2449,6 +2452,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
24492452 ArrayRef<Expr *> Args, DeclContext *LookupCtx,
24502453 TypoExpr **Out) {
24512454 DeclarationName Name = R.getLookupName();
2455+ SourceRange NameRange = R.getLookupNameInfo().getSourceRange();
24522456
24532457 unsigned diagnostic = diag::err_undeclared_var_use;
24542458 unsigned diagnostic_suggest = diag::err_undeclared_var_use_suggest;
@@ -2506,13 +2510,12 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
25062510 // We didn't find anything, so try to correct for a typo.
25072511 TypoCorrection Corrected;
25082512 if (S && Out) {
2509- SourceLocation TypoLoc = R.getNameLoc();
25102513 assert(!ExplicitTemplateArgs &&
25112514 "Diagnosing an empty lookup with explicit template args!");
25122515 *Out = CorrectTypoDelayed(
25132516 R.getLookupNameInfo(), R.getLookupKind(), S, &SS, CCC,
25142517 [=](const TypoCorrection &TC) {
2515- emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args ,
2518+ emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, NameRange ,
25162519 diagnostic, diagnostic_suggest);
25172520 },
25182521 nullptr, CTK_ErrorRecovery, LookupCtx);
@@ -2591,12 +2594,13 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
25912594 ? diag::note_implicit_param_decl
25922595 : diag::note_previous_decl;
25932596 if (SS.isEmpty())
2594- diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name,
2597+ diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name << NameRange ,
25952598 PDiag(NoteID), AcceptableWithRecovery);
25962599 else
2597- diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
2598- << Name << computeDeclContext(SS, false)
2599- << DroppedSpecifier << SS.getRange(),
2600+ diagnoseTypo(Corrected,
2601+ PDiag(diag::err_no_member_suggest)
2602+ << Name << computeDeclContext(SS, false)
2603+ << DroppedSpecifier << NameRange,
26002604 PDiag(NoteID), AcceptableWithRecovery);
26012605
26022606 // Tell the callee whether to try to recover.
@@ -2609,13 +2613,12 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
26092613 // FIXME: computing the declaration context might fail here (?)
26102614 if (!SS.isEmpty()) {
26112615 Diag(R.getNameLoc(), diag::err_no_member)
2612- << Name << computeDeclContext(SS, false)
2613- << SS.getRange();
2616+ << Name << computeDeclContext(SS, false) << NameRange;
26142617 return true;
26152618 }
26162619
26172620 // Give up, we can't recover.
2618- Diag(R.getNameLoc(), diagnostic) << Name;
2621+ Diag(R.getNameLoc(), diagnostic) << Name << NameRange ;
26192622 return true;
26202623}
26212624
0 commit comments