r224183 - Fix two small bugs in typo correction. One assertion failure building member expressions because the lookup finds a different name than the original, fixed by updating the LookupResult's name with the name of the found decl. Second is that we also diagnose delayed typo exprs in the index of an array subscript expression.

Nick Lewycky nicholas at mxc.ca
Fri Dec 12 18:54:29 PST 2014


Author: nicholas
Date: Fri Dec 12 20:54:28 2014
New Revision: 224183

URL: http://llvm.org/viewvc/llvm-project?rev=224183&view=rev
Log:
Fix two small bugs in typo correction. One assertion failure building member expressions because the lookup finds a different name than the original, fixed by updating the LookupResult's name with the name of the found decl. Second is that we also diagnose delayed typo exprs in the index of an array subscript expression.

The testcase shows a third bug with a FIXME in it.

Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=224183&r1=224182&r2=224183&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Dec 12 20:54:28 2014
@@ -1366,7 +1366,9 @@ Parser::ParsePostfixExpressionSuffix(Exp
                                               Idx.get(), RLoc);
       } else {
         (void)Actions.CorrectDelayedTyposInExpr(LHS);
+        (void)Actions.CorrectDelayedTyposInExpr(Idx);
         LHS = ExprError();
+        Idx = ExprError();
       }
 
       // Match the ']'.

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=224183&r1=224182&r2=224183&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Dec 12 20:54:28 2014
@@ -5961,9 +5961,10 @@ static ExprResult attemptRecovery(Sema &
     NewSS = *SS;
 
   if (auto *ND = TC.getCorrectionDecl()) {
+    R.setLookupName(ND->getDeclName());
     R.addDecl(ND);
     if (ND->isCXXClassMember()) {
-      // Figure out the correct naming class to ad to the LookupResult.
+      // Figure out the correct naming class to add to the LookupResult.
       CXXRecordDecl *Record = nullptr;
       if (auto *NNS = TC.getCorrectionSpecifier())
         Record = NNS->getAsType()->getAsCXXRecordDecl();

Modified: cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=224183&r1=224182&r2=224183&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp Fri Dec 12 20:54:28 2014
@@ -332,3 +332,27 @@ int test(Foo f) {
   return 0;
 }
 };
+
+namespace testMemberExprDeclarationNameInfo {
+  // The AST should only have the corrected name with no mention of 'data_'.
+  // FIXME: the second typo is being printed out with the location of the first
+  // because the TypoCorrection objects contain the SourceRange but the
+  // UnqualifiedTyposCorrected cache is keyed on IdentifierInfo.
+  void f(int);
+  struct S {
+    int data;  // expected-note 2{{'data' declared here}}
+    void m_fn1() {
+      data_[] =  // expected-error 2{{use of undeclared identifier 'data_'}}  expected-error {{expected expression}}
+          f(data_);
+    }
+  };
+}
+
+namespace testArraySubscriptIndex {
+  struct S {
+    int foodata;  // expected-note {{'foodata' declared here}}
+    void m_fn1() {
+      (+)[foodata_];  // expected-error{{expected expression}} expected-error {{use of undeclared identifier 'foodata_'; did you mean 'foodata'}}
+    }
+  };
+}





More information about the cfe-commits mailing list