re PR c++/71105 (lambdas with default captures improperly have function pointer conve...
authorPaolo Carlini <paolo.carlini@oracle.com>
Sun, 29 May 2016 08:05:30 +0000 (08:05 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 29 May 2016 08:05:30 +0000 (08:05 +0000)
/cp
2016-05-29  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/71105
* lambda.c (maybe_add_lambda_conv_op): Early return also when
LAMBDA_EXPR_DEFAULT_CAPTURE_MODE != CPLD_NONE.

/testsuite
2016-05-29  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/71105
* g++.dg/cpp0x/lambda/lambda-conv11.C: New.
* g++.dg/cpp1y/lambda-conv1.C: Likewise.
* g++.dg/cpp1y/lambda-conv2.C: Likewise.

From-SVN: r236859

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/lambda-conv2.C [new file with mode: 0644]

index 27fdbe1497aa88b9229ff7511c367efd1e25cdbe..7857e7fdce8c56327e0944edc8bfb8c740801b34 100644 (file)
@@ -1,3 +1,10 @@
+2016-05-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/71105
+       * g++.dg/cpp0x/lambda/lambda-conv11.C: New.
+       * g++.dg/cpp1y/lambda-conv1.C: Likewise.
+       * g++.dg/cpp1y/lambda-conv2.C: Likewise.
+
 2016-05-27  Jan Hubicka  <hubicka@ucw.cz>
 
        * gcc.dg/tree-ssa/prefetch-5.c: Remove xfail.
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C
new file mode 100644 (file)
index 0000000..4b8d648
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/71105
+// { dg-do compile { target c++11 } }
+
+void foo()
+{
+  int i;
+  static_cast<void(*)()>([i]{});  // { dg-error "invalid static_cast" }
+  static_cast<void(*)()>([=]{});  // { dg-error "invalid static_cast" }
+  static_cast<void(*)()>([&]{});  // { dg-error "invalid static_cast" }
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C
new file mode 100644 (file)
index 0000000..2e4ec49
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/71105
+// { dg-do compile { target c++14 } }
+
+void foo()
+{
+  int i;
+  static_cast<void(*)(int)>([i](auto){});  // { dg-error "invalid static_cast" }
+  static_cast<void(*)(int)>([=](auto){});  // { dg-error "invalid static_cast" }
+  static_cast<void(*)(int)>([&](auto){});  // { dg-error "invalid static_cast" }
+  static_cast<float(*)(float)>([i](auto x){ return x; });  // { dg-error "invalid static_cast" }
+  static_cast<float(*)(float)>([=](auto x){ return x; });  // { dg-error "invalid static_cast" }
+  static_cast<float(*)(float)>([&](auto x){ return x; });  // { dg-error "invalid static_cast" }
+}
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-conv2.C b/gcc/testsuite/g++.dg/cpp1y/lambda-conv2.C
new file mode 100644 (file)
index 0000000..45c0f3f
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/71105
+// { dg-do compile { target c++14 } }
+
+template <typename T> T declval();
+template <typename, typename> struct is_same
+{ static constexpr bool value = false; };
+template <typename T> struct is_same<T, T>
+{ static constexpr bool value = true; };
+
+template <class F>
+struct indirected : F {
+  indirected(F f) : F(f) {}
+  template <class I>
+  auto operator()(I i) -> decltype(declval<F&>()(*i)) {
+    return static_cast<F&>(*this)(*i);
+  }
+};
+
+int main() {
+  auto f = [=](auto i) { return i + i; };
+  auto i = indirected<decltype(f)>{f};
+  static_assert(is_same<decltype(i(declval<int*>())), int>::value, "");
+}