[cfe-commits] r130283 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/FixIt/typo.c test/FixIt/typo.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 26 20:47:06 PDT 2011


Author: dgregor
Date: Tue Apr 26 22:47:06 2011
New Revision: 130283

URL: http://llvm.org/viewvc/llvm-project?rev=130283&view=rev
Log:
Improve diagnostics for typo correction via Sema::ClassifyName(), by
looking at the context and the correction and using a custom
diagnostic. Also, enable some Fix-It tests that were somewhat lamely
disabled.

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

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=130283&r1=130282&r2=130283&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Apr 26 22:47:06 2011
@@ -510,12 +510,29 @@
     // close to this name.
     if (!SecondTry) {
       if (DeclarationName Corrected = CorrectTypo(Result, S, &SS)) {
+        unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
+        unsigned QualifiedDiag = diag::err_no_member_suggest;
+        
+        NamedDecl *FirstDecl = Result.empty()? 0 : *Result.begin();
+
+        if (getLangOptions().CPlusPlus && NextToken.is(tok::less) &&
+            FirstDecl && isa<TemplateDecl>(FirstDecl)) {
+          UnqualifiedDiag = diag::err_no_template_suggest;
+          QualifiedDiag = diag::err_no_member_template_suggest;
+        } else if (FirstDecl && 
+                   (isa<TypeDecl>(FirstDecl) || 
+                    isa<ObjCInterfaceDecl>(FirstDecl) ||
+                    isa<ObjCCompatibleAliasDecl>(FirstDecl))) {
+           UnqualifiedDiag = diag::err_unknown_typename_suggest;
+           QualifiedDiag = diag::err_unknown_nested_typename_suggest;
+         }
+        
         if (SS.isEmpty())
-          Diag(NameLoc, diag::err_undeclared_var_use_suggest)
+          Diag(NameLoc, UnqualifiedDiag)
             << Name << Corrected
             << FixItHint::CreateReplacement(NameLoc, Corrected.getAsString());
         else
-          Diag(NameLoc, diag::err_no_member_suggest)
+          Diag(NameLoc, QualifiedDiag)
             << Name << computeDeclContext(SS, false) << Corrected
             << SS.getRange()
             << FixItHint::CreateReplacement(NameLoc, Corrected.getAsString());
@@ -527,7 +544,6 @@
         if (Result.empty())
           return Corrected.getAsIdentifierInfo();
         
-        NamedDecl *FirstDecl = *Result.begin();
         Diag(FirstDecl->getLocation(), diag::note_previous_decl)
           << FirstDecl->getDeclName();
 

Modified: cfe/trunk/test/FixIt/typo.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.c?rev=130283&r1=130282&r2=130283&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo.c (original)
+++ cfe/trunk/test/FixIt/typo.c Tue Apr 26 22:47:06 2011
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: cp %s %t
-// RUN: %clang_cc1 -fsyntax-only -fixit -x c %t || true
+// RUN: not %clang_cc1 -fsyntax-only -fixit -x c %t
 // RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c %t
 // RUN: grep "Rectangle" %t
 struct Point {
@@ -30,7 +30,7 @@
   r1.top_left.x = 0;
 
   typedef struct Rectangle Rectangle; // expected-note{{'Rectangle' declared here}}
-  rectangle *r2 = &r1; // expected-error{{use of undeclared identifier 'rectangle'; did you mean 'Rectangle'?}}
+  rectangle *r2 = &r1; // expected-error{{ unknown type name 'rectangle'; did you mean 'Rectangle'?}}
   r2->top_left.y = 0;
   unsinged *ptr = 0; // expected-error{{use of undeclared identifier 'unsinged'; did you mean 'unsigned'?}}
   *ptr = 17;

Modified: cfe/trunk/test/FixIt/typo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.cpp?rev=130283&r1=130282&r2=130283&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo.cpp (original)
+++ cfe/trunk/test/FixIt/typo.cpp Tue Apr 26 22:47:06 2011
@@ -1,7 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: cp %s %t
-// RUN: %clang_cc1 -fsyntax-only -fixit -x c++ %t || true
+// RUN: not %clang_cc1 -fsyntax-only -fixit -x c++ %t
 // RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ %t
+// RUN: grep test_string %t
 
 namespace std {
   template<typename T> class basic_string { // expected-note 2{{'basic_string' declared here}}





More information about the cfe-commits mailing list