]> granicus.if.org Git - clang/commitdiff
Add a test for `const` folding introduced by r290297. NFC.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 27 Dec 2016 04:01:22 +0000 (04:01 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 27 Dec 2016 04:01:22 +0000 (04:01 +0000)
AFAICT, we didn't add a test targeted at the new "const can sometimes
act as constexpr" behavior introduced by r290297.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290577 91177308-0d34-0410-b5e6-96231b3b80d8

test/SemaCXX/constant-expression-cxx1y.cpp

index f8103224af89b25f473dac8883f3f675d76f334e..0a1877cc8c31f63d904900421c3d2fa9bd2e4a80 100644 (file)
@@ -957,3 +957,20 @@ namespace PR27989 {
   }
   static_assert(f(0) == 1, "");
 }
+
+namespace const_char {
+template <int M, int N>
+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<N>(Cs) == 'a' + 'b', "");
+}