This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to add test to cover case RANGE_FOR_STMT
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Thu, 11 Oct 2018 21:28:38 -0400
- Subject: C++ PATCH to add test to cover case RANGE_FOR_STMT
Recently it came up that no test in the testsuite triggers the RANGE_FOR_STMT
case in potential_constant_expression_1. I came up with this valid test that
tickles that codepath.
I can't use ({ }) instead of a lambda because the constexpr machinery doesn't
handle statement expressions; see default: in cxx_eval_constant_expression.
Tested on x86_64-linux, ok for trunk?
2018-10-11 Marek Polacek <polacek@redhat.com>
* g++.dg/cpp1z/constexpr-lambda22.C: New test,
diff --git gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
index e69de29bb2d..8bb473431a5 100644
--- gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
+++ gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C
@@ -0,0 +1,20 @@
+// { dg-do compile }
+// { dg-options -std=c++17 }
+
+#define SA(X) static_assert((X),#X)
+
+template<typename>
+constexpr int
+foo ()
+{
+ constexpr int a[] = { 1, 2, 3, 4, 5 };
+ int i = 0;
+ auto j = [&] {
+ for (auto x : a)
+ i++;
+ return i;
+ }();
+ return j;
+}
+
+SA (foo<int>() == 5);