C++1y: support simple variable assignments in constexpr functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180603 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 5f0908a..48860e0 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -845,7 +845,8 @@
<< (VD->getTLSKind() == VarDecl::TLS_Dynamic);
return false;
}
- if (SemaRef.RequireLiteralType(
+ if (!VD->getType()->isDependentType() &&
+ SemaRef.RequireLiteralType(
VD->getLocation(), VD->getType(),
diag::err_constexpr_local_var_non_literal_type,
isa<CXXConstructorDecl>(Dcl)))
@@ -1135,11 +1136,11 @@
// statement. We still do, unless the return type is void, because
// otherwise if there's no return statement, the function cannot
// be used in a core constant expression.
+ bool OK = getLangOpts().CPlusPlus1y && Dcl->getResultType()->isVoidType();
Diag(Dcl->getLocation(),
- getLangOpts().CPlusPlus1y && Dcl->getResultType()->isVoidType()
- ? diag::warn_cxx11_compat_constexpr_body_no_return
- : diag::err_constexpr_body_no_return);
- return false;
+ OK ? diag::warn_cxx11_compat_constexpr_body_no_return
+ : diag::err_constexpr_body_no_return);
+ return OK;
}
if (ReturnStmts.size() > 1) {
Diag(ReturnStmts.back(),
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 0e51399..3c942fa 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -97,6 +97,7 @@
DeclT = S.Context.getConstantArrayType(IAT->getElementType(),
ConstVal,
ArrayType::Normal, 0);
+ Str->setType(DeclT);
return;
}