re PR c++/87523 (ICE: Closures apparently fail to capture constexpr)
authorMarek Polacek <polacek@redhat.com>
Sat, 1 Dec 2018 21:53:07 +0000 (21:53 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sat, 1 Dec 2018 21:53:07 +0000 (21:53 +0000)
PR c++/87523
* g++.dg/cpp1y/lambda-generic-87523.C: New test.

From-SVN: r266714

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/lambda-generic-87523.C [new file with mode: 0644]

index 9dfc58d4d68d6d7e32e076009611b45a8614bfcd..2cdbba498b722685c5f6e1225a6491d481728edd 100644 (file)
@@ -40,6 +40,9 @@
        PR c++/79629
        * g++.dg/other/error35.C: New test.
 
+       PR c++/87523
+       * g++.dg/cpp1y/lambda-generic-87523.C: New test.
+
 2018-12-01  Jeff Law  <law@redhat.com>
 
        * gcc.dg/predict-22.c: Update expected output.
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-87523.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-87523.C
new file mode 100644 (file)
index 0000000..ecba1cf
--- /dev/null
@@ -0,0 +1,32 @@
+// PR c++/87523
+// { dg-do compile { target c++14 } }
+
+template <typename T, T v>
+struct my_integer_constant {
+    constexpr my_integer_constant() {}
+    constexpr operator T() const { return v; }
+    constexpr T operator()() const { return v; }
+};
+
+template <typename T, T... u>
+struct constant_call {
+    template <typename Callback>
+    static void call(T v, Callback f) {
+        char dummy[sizeof...(u)] = { ( (v == u) ? (f(my_integer_constant<T, u>{}), static_cast<char>(0)) : static_cast<char>(0))... };
+        (void)dummy;
+    }
+};
+
+void f(bool reverse_in, bool other_bool_in) {
+    auto helper = [&] (auto reverse_t) {
+        bool constexpr reverse_v = reverse_t;
+        (void)reverse_v;
+        constant_call<bool, true, false>::call(other_bool_in,
+                                               [&] (auto newb) {
+                                                   bool reverse_v_dyn = reverse_v;
+                                               });
+    };
+    constant_call<bool, true, false>::call(reverse_in, [&] (auto reverse_t) {
+            helper(reverse_t);
+        });
+}