diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx1y.cpp | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 660641eec6c..1eec2318e2b 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -880,7 +880,7 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl, diag::err_constexpr_local_var_non_literal_type, isa<CXXConstructorDecl>(Dcl))) return false; - if (!VD->hasInit()) { + if (!VD->hasInit() && !VD->isCXXForRangeDecl()) { SemaRef.Diag(VD->getLocation(), diag::err_constexpr_local_var_no_init) << isa<CXXConstructorDecl>(Dcl); diff --git a/clang/test/SemaCXX/constant-expression-cxx1y.cpp b/clang/test/SemaCXX/constant-expression-cxx1y.cpp index 136f7b198a8..521526ddba4 100644 --- a/clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx1y.cpp @@ -898,3 +898,16 @@ namespace PR17615 { }; constexpr int k = A().r; // expected-error {{constant expression}} expected-note {{in call to}} } + +namespace PR17331 { + template<typename T, unsigned int N> + constexpr T sum(const T (&arr)[N]) { + T result = 0; + for (T i : arr) + result += i; + return result; + } + + constexpr int ARR[] = { 1, 2, 3, 4, 5 }; + static_assert(sum(ARR) == 15, ""); +} |