aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2011-07-12 08:45:31 +0000
committerHans Wennborg <hans@hanshq.net>2011-07-12 08:45:31 +0000
commit701d1e77aca7e86348386fdeadcd56ca650f95ad (patch)
tree281a6097d309cdbf2380800c1668b72a67e5ffa9
parent91832368ef1c1158c4351bdccaa141dac818f04e (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134976 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExpr.cpp3
-rw-r--r--lib/Sema/SemaLookup.cpp3
-rw-r--r--test/SemaCXX/function-overload-typo-crash.cpp12
3 files changed, 15 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 2fa7b2515e..1e04ac734e 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -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())
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 0ecd81400b..7d075db0c4 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -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
index 0000000000..0fea312a97
--- /dev/null
+++ b/test/SemaCXX/function-overload-typo-crash.cpp
@@ -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'}}
+}