summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaStmt.cpp5
-rw-r--r--clang/test/SemaCXX/typo-correction-crash.cpp11
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index d73441646bb..836073a680c 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3069,6 +3069,11 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
QualType DeducedT = AT->getDeducedType();
if (!DeducedT.isNull() && !FD->isInvalidDecl()) {
AutoType *NewAT = Deduced->getContainedAutoType();
+ // It is possible that NewAT->getDeducedType() is null. When that happens,
+ // we should not crash, instead we ignore this deduction.
+ if (NewAT->getDeducedType().isNull())
+ return false;
+
CanQualType OldDeducedType = Context.getCanonicalFunctionResultType(
DeducedT);
CanQualType NewDeducedType = Context.getCanonicalFunctionResultType(
diff --git a/clang/test/SemaCXX/typo-correction-crash.cpp b/clang/test/SemaCXX/typo-correction-crash.cpp
new file mode 100644
index 00000000000..f01facd603e
--- /dev/null
+++ b/clang/test/SemaCXX/typo-correction-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+auto check1() {
+ return 1;
+ return s; // expected-error {{use of undeclared identifier 's'}}
+}
+
+int test = 11; // expected-note {{'test' declared here}}
+auto check2() {
+ return "s";
+ return tes; // expected-error {{use of undeclared identifier 'tes'; did you mean 'test'?}}
+}
OpenPOWER on IntegriCloud