From ddb49837aae8d36e6bd138bb356695deeb3b2e80 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 27 Dec 2016 04:01:22 +0000 Subject: [PATCH] Add a test for `const` folding introduced by r290297. NFC. AFAICT, we didn't add a test targeted at the new "const can sometimes act as constexpr" behavior introduced by r290297. llvm-svn: 290577 --- .../test/SemaCXX/constant-expression-cxx1y.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/clang/test/SemaCXX/constant-expression-cxx1y.cpp b/clang/test/SemaCXX/constant-expression-cxx1y.cpp index f8103224af89..0a1877cc8c31 100644 --- a/clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx1y.cpp @@ -957,3 +957,20 @@ namespace PR27989 { } static_assert(f(0) == 1, ""); } + +namespace const_char { +template +constexpr int sum(const char (&Arr)[N]) { + static_assert(N >= M, ""); + int S = 0; + for (unsigned I = 0; I != M; ++I) + S += Arr[I]; + return S; +} + +// As an extension, we support evaluating some things that are `const` as though +// they were `constexpr`. +const char Cs[] = {'a', 'b', 'c'}; +const int N = 2; +static_assert(sum(Cs) == 'a' + 'b', ""); +}