re PR c++/64085 (ICE on C++14 lambda by-reference capture with an initializer)
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 3 Apr 2015 17:23:27 +0000 (17:23 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 3 Apr 2015 17:23:27 +0000 (17:23 +0000)
/cp
2015-04-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/64085
* lambda.c (add_capture): Use dependent_type_p for capture by
reference too.

/testsuite
2015-04-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/64085
* g++.dg/cpp1y/lambda-init13.C: New.

From-SVN: r221858

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

index ca048aaaefbe13d8d64a792280ea8da4d39cc57b..b84f33746187c68b3c3bfc6747f00a170f9b5da6 100644 (file)
@@ -1,3 +1,9 @@
+2015-04-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/64085
+       * lambda.c (add_capture): Use dependent_type_p for capture by
+       reference too.
+
 2015-04-02  Marek Polacek  <polacek@redhat.com>
 
        PR c++/65642
index b160c8cb7ae16578d0090b7f804017f7c8ad3aa0..dd1c2d4337a2ee208e693f5f38a36d7d0a9ea102 100644 (file)
@@ -506,7 +506,7 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
       if (by_reference_p)
        {
          type = build_reference_type (type);
-         if (!real_lvalue_p (initializer))
+         if (!dependent_type_p (type) && !real_lvalue_p (initializer))
            error ("cannot capture %qE by reference", initializer);
        }
       else
index 0810c131b40ee22485a71d5c592a74c97c94d505..3e87768625a4da8854c0632a331013ebca834e87 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/64085
+       * g++.dg/cpp1y/lambda-init13.C: New.
+
 2015-04-03  Marek Polacek  <polacek@redhat.com>
 
        * g++.dg/cpp0x/pr57101.C: Use proper type for size_t.
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init13.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init13.C
new file mode 100644 (file)
index 0000000..9b1d139
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/64085
+// { dg-do compile { target c++14 } }
+
+template<typename T>
+struct reference_wrapper
+{
+  T& get() const noexcept;
+};
+
+template<class T>
+auto make_monad(reference_wrapper<T> arg) {
+  return [&captive = arg.get()](auto&&) { return 1; };
+}
+
+int main()
+{
+  make_monad(reference_wrapper<int&>());
+}