Index: clang/include/clang/Sema/Lookup.h =================================================================== --- clang/include/clang/Sema/Lookup.h +++ clang/include/clang/Sema/Lookup.h @@ -633,6 +633,10 @@ return NameInfo.getLoc(); } + SourceRange getNameRange() const { + return SourceRange(NameInfo.getBeginLoc(), NameInfo.getEndLoc()); + } + /// Get the Sema object that this lookup result is searching /// with. Sema &getSema() const { return *SemaPtr; } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -2173,7 +2173,7 @@ static void emitEmptyLookupTypoDiagnostic( const TypoCorrection &TC, Sema &SemaRef, const CXXScopeSpec &SS, - DeclarationName Typo, SourceLocation TypoLoc, ArrayRef Args, + DeclarationName Typo, SourceRange TypoRange, ArrayRef Args, unsigned DiagnosticID, unsigned DiagnosticSuggestID) { DeclContext *Ctx = SS.isEmpty() ? nullptr : SemaRef.computeDeclContext(SS, false); @@ -2181,10 +2181,10 @@ // Emit a special diagnostic for failed member lookups. // FIXME: computing the declaration context might fail here (?) if (Ctx) - SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << Ctx - << SS.getRange(); + SemaRef.Diag(TypoRange.getBegin(), diag::err_no_member) + << Typo << Ctx << TypoRange; else - SemaRef.Diag(TypoLoc, DiagnosticID) << Typo; + SemaRef.Diag(TypoRange.getEnd(), DiagnosticID) << Typo << TypoRange; return; } @@ -2198,9 +2198,9 @@ SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo, SemaRef.PDiag(NoteID)); else - SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest) - << Typo << Ctx << DroppedSpecifier - << SS.getRange(), + SemaRef.diagnoseTypo(TC, + SemaRef.PDiag(diag::err_no_member_suggest) + << Typo << Ctx << DroppedSpecifier << TypoRange, SemaRef.PDiag(NoteID)); } @@ -2324,16 +2324,16 @@ DC = DC->getLookupParent(); } + SourceRange TypoRange = R.getNameRange(); // We didn't find anything, so try to correct for a typo. TypoCorrection Corrected; if (S && Out) { - SourceLocation TypoLoc = R.getNameLoc(); assert(!ExplicitTemplateArgs && "Diagnosing an empty lookup with explicit template args!"); *Out = CorrectTypoDelayed( R.getLookupNameInfo(), R.getLookupKind(), S, &SS, CCC, [=](const TypoCorrection &TC) { - emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoLoc, Args, + emitEmptyLookupTypoDiagnostic(TC, *this, SS, Name, TypoRange, Args, diagnostic, diagnostic_suggest); }, nullptr, CTK_ErrorRecovery); @@ -2436,7 +2436,7 @@ } // Give up, we can't recover. - Diag(R.getNameLoc(), diagnostic) << Name; + Diag(R.getNameLoc(), diagnostic) << Name << TypoRange; return true; }