]> granicus.if.org Git - clang/commitdiff
Fix typo correction crash on overloaded functions, pr10283.
authorHans Wennborg <hans@hanshq.net>
Tue, 12 Jul 2011 08:45:31 +0000 (08:45 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 12 Jul 2011 08:45:31 +0000 (08:45 +0000)
It would be cool if we could do overload resolution to suggest
the right function, but at least this fixes the crashing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134976 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
lib/Sema/SemaLookup.cpp
test/SemaCXX/function-overload-typo-crash.cpp [new file with mode: 0644]

index 2fa7b2515ef1cb3651be25c1ce1383a1555d512c..1e04ac734e60a2159bd32fd4a3d9c4098f4e5d44 100644 (file)
@@ -1404,8 +1404,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
     std::string CorrectedQuotedStr(Corrected.getQuoted(getLangOptions()));
     R.setLookupName(Corrected.getCorrection());
 
-    if (!Corrected.isKeyword()) {
-      NamedDecl *ND = Corrected.getCorrectionDecl();
+    if (NamedDecl *ND = Corrected.getCorrectionDecl()) {
       R.addDecl(ND);
       if (isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)) {
         if (SS.isEmpty())
index 0ecd81400b0bacea753a33f5788b1ed1ba9e0169..7d075db0c44235aa227861a7289586dc920a0130 100644 (file)
@@ -3744,6 +3744,8 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
       case LookupResult::FoundOverloaded:
       case LookupResult::FoundUnresolvedValue:
         I->second.setCorrectionDecl(TmpRes.getAsSingle<NamedDecl>());
+        // FIXME: This sets the CorrectionDecl to NULL for overloaded functions.
+        // It would be nice to find the right one with overload resolution.
         ++I;
         break;
       }
@@ -3835,7 +3837,6 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
     // wasn't actually in scope.
     if (ED == 0 && Result.isKeyword()) return TypoCorrection();
 
-    assert(Result.isResolved() && "correction has not been looked up");
     // Record the correction for unqualified lookup.
     if (IsUnqualifiedLookup)
       UnqualifiedTyposCorrected[Typo] = Result;
diff --git a/test/SemaCXX/function-overload-typo-crash.cpp b/test/SemaCXX/function-overload-typo-crash.cpp
new file mode 100644 (file)
index 0000000..0fea312
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR10283
+void min();
+void min(int);
+
+template <typename T> void max(T);
+
+void f() {
+  fin(); //expected-error {{use of undeclared identifier 'fin'; did you mean 'min'}}
+  fax(0); //expected-error {{use of undeclared identifier 'fax'; did you mean 'max'}}
+}