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 6e8680b..b1e3edc 100644 (file)
@@ -1,5 +1,10 @@
 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
        * g++.dg/cpp1y/lambda-generic-78018.C: New.
 
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{})) { } 
+}