aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2017-11-15 13:18:09 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2017-11-15 13:18:09 +0000
commit03ab2eb725851203ccc34ca3210439801812a6be (patch)
tree11000c7700a2d61a46ce3a7e455d12e6a4694c66 /gcc
parent17bae2cadb4e28940545cc4fdb6223ca7e21ed60 (diff)
downloadgcc-03ab2eb725851203ccc34ca3210439801812a6be.zip
gcc-03ab2eb725851203ccc34ca3210439801812a6be.tar.gz
gcc-03ab2eb725851203ccc34ca3210439801812a6be.tar.bz2
[PR c++/81574] lambda capture of function reference
https://gcc.gnu.org/ml/gcc-patches/2017-11/msg01200.html PR c++/81574 * lambda.c (lambda_capture_field_type): Function references are always catured by reference. PR c++/81574 * g++.dg/cpp1y/pr81574.C: New. From-SVN: r254768
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/lambda.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/pr81574.C13
4 files changed, 26 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 839042e..e8c882f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2017-11-15 Nathan Sidwell <nathan@acm.org>
+
+ PR c++/81574
+ * lambda.c (lambda_capture_field_type): Function references are
+ always catured by reference.
+
2017-11-15 Martin Liska <mliska@suse.cz>
* decl.c (begin_destructor_body): Use cp_build_fold_indirect_ref
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index 2cbad87..4480c67 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -245,7 +245,8 @@ lambda_capture_field_type (tree expr, bool explicit_init_p,
{
type = non_reference (unlowered_expr_type (expr));
- if (!is_this && by_reference_p)
+ if (!is_this
+ && (by_reference_p || TREE_CODE (type) == FUNCTION_TYPE))
type = build_reference_type (type);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1dada43..8478a7a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-15 Nathan Sidwell <nathan@acm.org>
+
+ PR c++/81574
+ * g++.dg/cpp1y/pr81574.C: New.
+
2017-11-15 Richard Biener <rguenther@suse.de>
PR tree-optimization/82985
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr81574.C b/gcc/testsuite/g++.dg/cpp1y/pr81574.C
new file mode 100644
index 0000000..f9949ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr81574.C
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++14 } }
+// PR c++/81574 references to functions are captured by reference.
+
+// 8.1.5.2/10
+// For each entity captured by copy, ... an lvalue reference to the
+// referenced function type if the entity is a reference to a function
+
+void f (void (&b)())
+{
+ [=] { b; } ();
+ [=, b(f)] { b; } ();
+ [=, b(b)] { b; } ();
+}