From: Douglas Gregor Date: Tue, 29 Jun 2010 19:27:42 +0000 (+0000) Subject: When typo correction produces a result that is not of the kind we're X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=12eb5d6aa882eb247a6c22225b625eee04217105;p=clang When typo correction produces a result that is not of the kind we're looking for, reset the name within the LookupResult structure in addition to clearing out the results. Fixes PR7508. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107197 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index c0ec9e997d..42c346fbe8 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -458,8 +458,10 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S, if (NamedDecl *ND = Found.getAsSingle()) Diag(ND->getLocation(), diag::note_previous_decl) << ND->getDeclName(); - } else + } else { Found.clear(); + Found.setLookupName(&II); + } } NamedDecl *SD = Found.getAsSingle(); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index bf75773f6d..63452f9cbc 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1139,6 +1139,7 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD, return true; R.clear(); + R.setLookupName(MemberOrBase); } } @@ -3516,6 +3517,9 @@ Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S, << Corrected; NamespcName = Corrected.getAsIdentifierInfo(); + } else { + R.clear(); + R.setLookupName(NamespcName); } } } @@ -4240,6 +4244,9 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S, << Corrected; Ident = Corrected.getAsIdentifierInfo(); + } else { + R.clear(); + R.setLookupName(Ident); } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index e5c8e973c5..ae16d57870 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2620,6 +2620,7 @@ LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R, return false; } else { R.clear(); + R.setLookupName(Name); } return false; @@ -3080,6 +3081,9 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr, IV->getNameAsString()); Diag(IV->getLocation(), diag::note_previous_decl) << IV->getDeclName(); + } else { + Res.clear(); + Res.setLookupName(Member); } } diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 735809f185..7e5377ab9a 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -258,7 +258,7 @@ void Sema::LookupTemplateName(LookupResult &Found, // If we did not find any names, attempt to correct any typos. DeclarationName Name = Found.getLookupName(); if (DeclarationName Corrected = CorrectTypo(Found, S, &SS, LookupCtx, - false, CTC_CXXCasts)) { + false, CTC_CXXCasts)) { FilterAcceptableTemplateNames(Context, Found); if (!Found.empty()) { if (LookupCtx) @@ -277,6 +277,7 @@ void Sema::LookupTemplateName(LookupResult &Found, } } else { Found.clear(); + Found.setLookupName(Name); } } diff --git a/test/SemaCXX/member-expr.cpp b/test/SemaCXX/member-expr.cpp index e83fdbf087..6830c5fdaf 100644 --- a/test/SemaCXX/member-expr.cpp +++ b/test/SemaCXX/member-expr.cpp @@ -90,3 +90,14 @@ namespace test5 { x->A::foo(); // expected-error {{'test5::A' is not a pointer}} } } + +namespace PR7508 { + struct A { + struct CleanupScope {}; + void PopCleanupBlock(); + }; + + void foo(A &a) { + a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'}} + } +}