re PR c++/78131 (Inconsistent evaluation for `constexpr` lambdas in templates between...
authorPaolo Carlini <paolo.carlini@oracle.com>
Wed, 4 Oct 2017 20:58:52 +0000 (20:58 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 4 Oct 2017 20:58:52 +0000 (20:58 +0000)
2017-10-04  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/78131
* g++.dg/cpp1z/constexpr-lambda17.C: New.

From-SVN: r253431

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/constexpr-lambda17.C [new file with mode: 0644]

index 6e8680b3312f121364461c224cca29ba4f3dd749..b1e3edcb828a25c491e11277e7866b0ec067c2e7 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-04  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/78131
+       * g++.dg/cpp1z/constexpr-lambda17.C: New.
+
 2017-10-04  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/78018
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda17.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda17.C
new file mode 100644 (file)
index 0000000..44bd2b8
--- /dev/null
@@ -0,0 +1,30 @@
+// PR c++/78131
+// { dg-options -std=c++17 }
+
+template <typename TF>
+constexpr auto f(TF)
+{
+    return [](auto...) constexpr { return true; };
+}   
+
+// Compiles and works as intended.
+template <typename T0>
+void ok_0(T0)
+{
+    static_assert(f([](auto x) -> decltype(x){})(T0{}));
+}
+
+// Compiles and works as intended.
+template <typename T0>
+void ok_1(T0)
+{
+    constexpr auto a = f([](auto x) -> decltype(x){})(T0{});
+    if constexpr(a) { }
+}
+
+// Compile-time error!
+template <typename T0>
+void fail_0(T0)
+{
+    if constexpr(f([](auto x) -> decltype(x){})(T0{})) { } 
+}