[cfe-commits] r92879 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/FixIt/typo.cpp test/Sema/switch.c

Douglas Gregor dgregor at apple.com
Wed Jan 6 16:31:31 PST 2010


Author: dgregor
Date: Wed Jan  6 18:31:29 2010
New Revision: 92879

URL: http://llvm.org/viewvc/llvm-project?rev=92879&view=rev
Log:
Fix the search for visible declarations within a Scope to ensure that
we look into a Scope that corresponds to a compound statement whose
scope was combined with the scope of the function that owns it. This
improves typo correction in many common cases.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/FixIt/typo.cpp
    cfe/trunk/test/Sema/switch.c

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=92879&r1=92878&r2=92879&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jan  6 18:31:29 2010
@@ -2000,6 +2000,19 @@
   if (!S)
     return;
 
+  if (!S->getEntity() || !S->getParent() ||
+      ((DeclContext *)S->getEntity())->isFunctionOrMethod()) {
+    // Walk through the declarations in this Scope.
+    for (Scope::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
+         D != DEnd; ++D) {
+      if (NamedDecl *ND = dyn_cast<NamedDecl>((Decl *)((*D).get())))
+        if (Result.isAcceptableDecl(ND)) {
+          Consumer.FoundDecl(ND, Visited.checkHidden(ND));
+          Visited.add(ND);
+        }
+    }
+  }
+  
   DeclContext *Entity = 0;
   if (S->getEntity()) {
     // Look into this scope's declaration context, along with any of its
@@ -2041,22 +2054,11 @@
     // doing so would force the normal C++ name-lookup code to look into the
     // translation unit decl when the IdentifierInfo chains would suffice. 
     // Once we fix that problem (which is part of a more general "don't look
-    // in DeclContexts unless we have to" optimization), we can eliminate the
-    // TranslationUnit parameter entirely.
+    // in DeclContexts unless we have to" optimization), we can eliminate this.
     Entity = Result.getSema().Context.getTranslationUnitDecl();
     LookupVisibleDecls(Entity, Result, /*QualifiedNameLookup=*/false, 
                        Consumer, Visited);
-  } else {
-    // Walk through the declarations in this Scope.
-    for (Scope::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
-         D != DEnd; ++D) {
-      if (NamedDecl *ND = dyn_cast<NamedDecl>((Decl *)((*D).get())))
-        if (Result.isAcceptableDecl(ND)) {
-          Consumer.FoundDecl(ND, Visited.checkHidden(ND));
-          Visited.add(ND);
-        }
-    }
-  }
+  } 
   
   if (Entity) {
     // Lookup visible declarations in any namespaces found by using

Modified: cfe/trunk/test/FixIt/typo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.cpp?rev=92879&r1=92878&r2=92879&view=diff

==============================================================================
--- cfe/trunk/test/FixIt/typo.cpp (original)
+++ cfe/trunk/test/FixIt/typo.cpp Wed Jan  6 18:31:29 2010
@@ -21,8 +21,9 @@
 
 ::other_std::string str3; // expected-error{{no member named 'other_std' in the global namespace; did you mean 'otherstd'?}}
 
-float area(float radius, float pi) {
-  return radious * pi; // expected-error{{use of undeclared identifier 'radious'; did you mean 'radius'?}}
+float area(float radius, // expected-note{{'radius' declared here}}
+           float pi) {
+  return radious * pi; // expected-error{{did you mean 'radius'?}}
 }
 
 bool test_string(std::string s) {

Modified: cfe/trunk/test/Sema/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch.c?rev=92879&r1=92878&r2=92879&view=diff

==============================================================================
--- cfe/trunk/test/Sema/switch.c (original)
+++ cfe/trunk/test/Sema/switch.c Wed Jan  6 18:31:29 2010
@@ -76,7 +76,7 @@
 }
 
 // PR5606
-int f0(int var) {
+int f0(int var) { // expected-note{{'var' declared here}}
   switch (va) { // expected-error{{use of undeclared identifier 'va'}}
   case 1:
     break;





More information about the cfe-commits mailing list