[cfe-commits] r134976 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaLookup.cpp test/SemaCXX/function-overload-typo-crash.cpp

Hans Wennborg hans at hanshq.net
Tue Jul 12 01:45:31 PDT 2011


Author: hans
Date: Tue Jul 12 03:45:31 2011
New Revision: 134976

URL: http://llvm.org/viewvc/llvm-project?rev=134976&view=rev
Log:
Fix typo correction crash on overloaded functions, pr10283.

It would be cool if we could do overload resolution to suggest
the right function, but at least this fixes the crashing.

Added:
    cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=134976&r1=134975&r2=134976&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul 12 03:45:31 2011
@@ -1404,8 +1404,7 @@
     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())

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=134976&r1=134975&r2=134976&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Jul 12 03:45:31 2011
@@ -3744,6 +3744,8 @@
       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 @@
     // 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;

Added: cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp?rev=134976&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp (added)
+++ cfe/trunk/test/SemaCXX/function-overload-typo-crash.cpp Tue Jul 12 03:45:31 2011
@@ -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'}}
+}





More information about the cfe-commits mailing list