Handle a difference in lambda return type deduction between C++11 and C++1y: if
no return type is specified, C++11 will deduce a cv-qualified return type in
some cases, but C++1y never will.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187275 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 7feb96f..61319d2 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -2376,9 +2376,15 @@
return StmtError();
RetValExp = Result.take();
- if (!CurContext->isDependentContext())
+ if (!CurContext->isDependentContext()) {
FnRetType = RetValExp->getType();
- else
+ // In C++11, we take the type of the expression after decay and
+ // lvalue-to-rvalue conversion, so a class type can be cv-qualified.
+ // In C++1y, we perform template argument deduction as if the return
+ // type were 'auto', so an implicit return type is never cv-qualified.
+ if (getLangOpts().CPlusPlus1y && FnRetType.hasQualifiers())
+ FnRetType = FnRetType.getUnqualifiedType();
+ } else
FnRetType = CurCap->ReturnType = Context.DependentTy;
} else {
if (RetValExp) {