From de6d6c486031bacf3097831dd9fe95b9dab59fe9 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 29 Dec 2015 19:43:10 +0000 Subject: Teach typo correction to properly handle mapping declarations to their underlying decls. Preserve the found declaration throughout, and only map to the underlying declaration when we want to check whether it's the right kind. This allows us to provide the right source location for the found declaration, and prepares for the possibility of underlying decls with a different name from the found decl. llvm-svn: 256575 --- clang/lib/Sema/SemaExpr.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'clang/lib/Sema/SemaExpr.cpp') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 434b421afb6..888319b395c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1776,10 +1776,9 @@ static void emitEmptyLookupTypoDiagnostic( std::string CorrectedStr = TC.getAsString(SemaRef.getLangOpts()); bool DroppedSpecifier = TC.WillReplaceSpecifier() && Typo.getAsString() == CorrectedStr; - unsigned NoteID = - (TC.getCorrectionDecl() && isa(TC.getCorrectionDecl())) - ? diag::note_implicit_param_decl - : diag::note_previous_decl; + unsigned NoteID = TC.getCorrectionDeclAs() + ? diag::note_implicit_param_decl + : diag::note_previous_decl; if (!Ctx) SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo, SemaRef.PDiag(NoteID)); @@ -1903,7 +1902,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, bool AcceptableWithRecovery = false; bool AcceptableWithoutRecovery = false; - NamedDecl *ND = Corrected.getCorrectionDecl(); + NamedDecl *ND = Corrected.getFoundDecl(); if (ND) { if (Corrected.isOverloaded()) { OverloadCandidateSet OCS(R.getNameLoc(), @@ -1922,7 +1921,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, } switch (OCS.BestViableFunction(*this, R.getNameLoc(), Best)) { case OR_Success: - ND = Best->Function; + ND = Best->FoundDecl; Corrected.setCorrectionDecl(ND); break; default: @@ -1944,15 +1943,16 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, R.setNamingClass(Record); } - AcceptableWithRecovery = - isa(ND) || isa(ND); + auto *UnderlyingND = ND->getUnderlyingDecl(); + AcceptableWithRecovery = isa(UnderlyingND) || + isa(UnderlyingND); // FIXME: If we ended up with a typo for a type name or // Objective-C class name, we're in trouble because the parser // is in the wrong place to recover. Suggest the typo // correction, but don't make it a fix-it since we're not going // to recover well anyway. AcceptableWithoutRecovery = - isa(ND) || isa(ND); + isa(UnderlyingND) || isa(UnderlyingND); } else { // FIXME: We found a keyword. Suggest it, but don't provide a fix-it // because we aren't able to recover. @@ -1960,8 +1960,7 @@ Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, } if (AcceptableWithRecovery || AcceptableWithoutRecovery) { - unsigned NoteID = (Corrected.getCorrectionDecl() && - isa(Corrected.getCorrectionDecl())) + unsigned NoteID = Corrected.getCorrectionDeclAs() ? diag::note_implicit_param_decl : diag::note_previous_decl; if (SS.isEmpty()) @@ -4402,7 +4401,7 @@ static TypoCorrection TryTypoCorrectionForCall(Sema &S, Expr *Fn, llvm::make_unique(S, FuncName.getAsIdentifierInfo(), Args.size(), ME), Sema::CTK_ErrorRecovery)) { - if (NamedDecl *ND = Corrected.getCorrectionDecl()) { + if (NamedDecl *ND = Corrected.getFoundDecl()) { if (Corrected.isOverloaded()) { OverloadCandidateSet OCS(NameLoc, OverloadCandidateSet::CSK_Normal); OverloadCandidateSet::iterator Best; @@ -4413,16 +4412,16 @@ static TypoCorrection TryTypoCorrectionForCall(Sema &S, Expr *Fn, } switch (OCS.BestViableFunction(S, NameLoc, Best)) { case OR_Success: - ND = Best->Function; + ND = Best->FoundDecl; Corrected.setCorrectionDecl(ND); break; default: break; } } - if (isa(ND) || isa(ND)) { + ND = ND->getUnderlyingDecl(); + if (isa(ND) || isa(ND)) return Corrected; - } } } return TypoCorrection(); -- cgit v1.2.3