Commit 174ebf65 by Ville Voutilainen Committed by Jason Merrill

re PR c++/61133 (g++ doesn't implement DR1760)

	PR c++/61133
	* lambda.c (build_capture_proxy, add_capture): Treat normal
	captures and init-captures identically.

From-SVN: r210720
parent 2acb1027
2014-05-21 Ville Voutilainen <ville.voutilainen@gmail.com>
PR c++/61133
* lambda.c (build_capture_proxy, add_capture): Treat normal
captures and init-captures identically.
2014-05-21 Mark Wielaard <mjw@redhat.com> 2014-05-21 Mark Wielaard <mjw@redhat.com>
PR debug/16063 PR debug/16063
......
...@@ -367,10 +367,7 @@ build_capture_proxy (tree member) ...@@ -367,10 +367,7 @@ build_capture_proxy (tree member)
object = TREE_OPERAND (object, 0); object = TREE_OPERAND (object, 0);
/* Remove the __ inserted by add_capture. */ /* Remove the __ inserted by add_capture. */
if (DECL_NORMAL_CAPTURE_P (member)) name = get_identifier (IDENTIFIER_POINTER (DECL_NAME (member)) + 2);
name = get_identifier (IDENTIFIER_POINTER (DECL_NAME (member)) + 2);
else
name = DECL_NAME (member);
type = lambda_proxy_type (object); type = lambda_proxy_type (object);
...@@ -500,17 +497,11 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p, ...@@ -500,17 +497,11 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
won't find the field with name lookup. We can't just leave the name won't find the field with name lookup. We can't just leave the name
unset because template instantiation uses the name to find unset because template instantiation uses the name to find
instantiated fields. */ instantiated fields. */
if (!explicit_init_p) buf = (char *) alloca (IDENTIFIER_LENGTH (id) + 3);
{ buf[1] = buf[0] = '_';
buf = (char *) alloca (IDENTIFIER_LENGTH (id) + 3); memcpy (buf + 2, IDENTIFIER_POINTER (id),
buf[1] = buf[0] = '_'; IDENTIFIER_LENGTH (id) + 1);
memcpy (buf + 2, IDENTIFIER_POINTER (id), name = get_identifier (buf);
IDENTIFIER_LENGTH (id) + 1);
name = get_identifier (buf);
}
else
/* But captures with explicit initializers are named. */
name = id;
/* If TREE_TYPE isn't set, we're still in the introducer, so check /* If TREE_TYPE isn't set, we're still in the introducer, so check
for duplicates. */ for duplicates. */
......
// Test that simple captures are not named in the closure type, but // Test that captures are not named in the closure type.
// initialized captures are named.
// { dg-do compile { target c++1y } } // { dg-do compile { target c++1y } }
int main() int main()
{ {
int i; int i;
auto lam = [i,j=42]{}; auto lam = [i,j=42]{};
lam.j; lam.j; // { dg-error "no member" }
lam.j.foo; // { dg-error "::j" }
lam.i; // { dg-error "no member" } lam.i; // { dg-error "no member" }
} }
// DR1760: "no additional copy and destruction is performed"
// { dg-do run { target c++1y } }
#include <cassert>
int copy_count = 0;
int dtor_count = 0;
struct X
{
X() = default;
X(const X&) { ++copy_count; }
~X() { ++dtor_count; }
};
int main()
{
{
X x;
auto z = [y = x](){};
X x2;
auto z2 = [x2](){};
assert(copy_count == 2);
}
assert(dtor_count == 4);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment