summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2019-05-08 05:49:42 +0000
committerSam McCall <sam.mccall@gmail.com>2019-05-08 05:49:42 +0000
commit835d67f6c7e78dd730d9ab7e55af23612d644067 (patch)
tree49bd0d76b1c4f8a7dd656d6227db47189e93b9af /clang/lib/Sema
parent0a753938db3b2db756b6c535c2127d4efaaa0b40 (diff)
downloadbcm5719-llvm-835d67f6c7e78dd730d9ab7e55af23612d644067.tar.gz
bcm5719-llvm-835d67f6c7e78dd730d9ab7e55af23612d644067.zip
[Sema] Correct typos in return statements so the return types of 'auto' functions are always deduced.
Summary: e.g. auto foo() { return no_such_thing; // Return value is a TypoExpr } using T = decltype(foo()); // Uh-oh, undeduced auto. Reviewers: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61649 llvm-svn: 360224
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index fe0cf744964..c7fb5654516 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Sema/Ownership.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDiagnostic.h"
@@ -3503,7 +3504,12 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD,
StmtResult
Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
Scope *CurScope) {
- StmtResult R = BuildReturnStmt(ReturnLoc, RetValExp);
+ // Correct typos, in case the containing function returns 'auto' and
+ // RetValExp should determine the deduced type.
+ ExprResult RetVal = CorrectDelayedTyposInExpr(RetValExp);
+ if (RetVal.isInvalid())
+ return StmtError();
+ StmtResult R = BuildReturnStmt(ReturnLoc, RetVal.get());
if (R.isInvalid() || ExprEvalContexts.back().Context ==
ExpressionEvaluationContext::DiscardedStatement)
return R;
OpenPOWER on IntegriCloud