From: Richard Smith Date: Tue, 13 Mar 2012 20:58:32 +0000 (+0000) Subject: Allow vectors to be constructed from constexpr function arguments in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b1f684416980ef6f1a7cb9e6af9c4fa4a164617;p=clang Allow vectors to be constructed from constexpr function arguments in constant expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152665 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 4531a46448..7d65cf585b 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -3743,7 +3743,7 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) { llvm::APSInt sInt(32); if (CountInits < NumInits) { if (!EvaluateInteger(E->getInit(CountInits), sInt, Info)) - return Error(E); + return false; } else // trailing integer zero. sInt = Info.Ctx.MakeIntValue(0, EltTy); Elements.push_back(APValue(sInt)); @@ -3752,7 +3752,7 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) { llvm::APFloat f(0.0); if (CountInits < NumInits) { if (!EvaluateFloat(E->getInit(CountInits), f, Info)) - return Error(E); + return false; } else // trailing float zero. f = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(EltTy)); Elements.push_back(APValue(f)); diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index 66fd064fed..41d214a636 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -1230,3 +1230,17 @@ namespace CompoundLiteral { // in C++, and in C we model compound literals as lvalues. constexpr int *p = (int*)(int[1]){0}; // expected-warning {{C99}} expected-error {{constant expression}} expected-note 2{{temporary}} } + +namespace Vector { + typedef int __attribute__((vector_size(16))) VI4; + constexpr VI4 f(int n) { + return VI4 { n * 3, n + 4, n - 5, n / 6 }; + } + constexpr auto v1 = f(10); + + typedef double __attribute__((vector_size(32))) VD4; + constexpr VD4 g(int n) { + return (VD4) { n / 2.0, n + 1.5, n - 5.4, n * 0.9 }; // expected-warning {{C99}} + } + constexpr auto v2 = g(4); +}