[cfe-commits] r92348 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaTemplate.cpp test/FixIt/typo.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 31 00:11:17 PST 2009


Author: dgregor
Date: Thu Dec 31 02:11:17 2009
New Revision: 92348

URL: http://llvm.org/viewvc/llvm-project?rev=92348&view=rev
Log:
Typo correction for template names, e.g.,

typo.cpp:27:8: error: no template named 'basic_sting' in namespace 'std'; 
    did you mean 'basic_string'?
  std::basic_sting<char> b2;
  ~~~~~^~~~~~~~~~~
       basic_string


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/FixIt/typo.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=92348&r1=92347&r2=92348&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Dec 31 02:11:17 2009
@@ -2557,6 +2557,9 @@
   "use of undeclared %0; did you mean %1?">;
 def err_undeclared_var_use_suggest : Error<
   "use of undeclared identifier %0; did you mean %1?">;
+def err_no_template_suggest : Error<"no template named %0; did you mean %1?">;
+def err_no_member_template_suggest : Error<
+  "no template named %0 in %1; did you mean %2?">;
 
 }
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Dec 31 02:11:17 2009
@@ -102,7 +102,8 @@
 
   QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
 
-  LookupResult R(*this, TName, SourceLocation(), LookupOrdinaryName);
+  LookupResult R(*this, TName, Name.getSourceRange().getBegin(), 
+                 LookupOrdinaryName);
   R.suppressDiagnostics();
   LookupTemplateName(R, S, SS, ObjectType, EnteringContext);
   if (R.empty())
@@ -202,6 +203,29 @@
   assert(!Found.isAmbiguous() &&
          "Cannot handle template name-lookup ambiguities");
 
+  if (Found.empty()) {
+    // If we did not find any names, attempt to correct any typos.
+    DeclarationName Name = Found.getLookupName();
+    if (CorrectTypo(Found, S, &SS, LookupCtx)) {
+      FilterAcceptableTemplateNames(Context, Found);
+      if (!Found.empty() && isa<TemplateDecl>(*Found.begin())) {
+        if (LookupCtx)
+          Diag(Found.getNameLoc(), diag::err_no_member_template_suggest)
+            << Name << LookupCtx << Found.getLookupName() << SS.getRange()
+            << CodeModificationHint::CreateReplacement(Found.getNameLoc(),
+                                          Found.getLookupName().getAsString());
+        else
+          Diag(Found.getNameLoc(), diag::err_no_template_suggest)
+            << Name << Found.getLookupName()
+            << CodeModificationHint::CreateReplacement(Found.getNameLoc(),
+                                          Found.getLookupName().getAsString());
+      } else
+        Found.clear();
+    } else {
+      Found.clear();
+    }
+  }
+
   FilterAcceptableTemplateNames(Context, Found);
   if (Found.empty())
     return;

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

==============================================================================
--- cfe/trunk/test/FixIt/typo.cpp (original)
+++ cfe/trunk/test/FixIt/typo.cpp Thu Dec 31 02:11:17 2009
@@ -23,6 +23,10 @@
 }
 
 bool test_string(std::string s) {
+  basc_string<char> b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}}
+  std::basic_sting<char> b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}}
+  (void)b1;
+  (void)b2;
   return s.fnd("hello") // expected-error{{no member named 'fnd' in 'class std::basic_string<char>'; did you mean 'find'?}}
     == std::string::pos; // expected-error{{no member named 'pos' in 'class std::basic_string<char>'; did you mean 'npos'?}}
 }





More information about the cfe-commits mailing list