From: Jason Merrill Date: Mon, 22 Apr 2013 18:52:50 +0000 (-0400) Subject: Core 1612 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=08afbd3bcaa0c6ca8ec54fddaf80dac5b97a659c;p=gcc.git Core 1612 Core 1612 * semantics.c (finish_id_expression): Reject capture of anonymous union member. From-SVN: r198153 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0dada14784a..b8c4727d6ae 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-04-22 Jason Merrill + Core 1612 + * semantics.c (finish_id_expression): Reject capture of anonymous + union member. + Core 1609 * decl2.c (check_default_args): Check for pack expansion. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2784d797bdb..391dc1e558a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3105,6 +3105,12 @@ finish_id_expression (tree id_expression, = decl_function_context (containing_function); } + if (lambda_expr && TREE_CODE (decl) == VAR_DECL + && DECL_ANON_UNION_VAR_P (decl)) + { + error ("cannot capture member %qD of anonymous union", decl); + return error_mark_node; + } if (context == containing_function) { decl = add_default_capture (lambda_stack, diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-anon1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-anon1.C new file mode 100644 index 00000000000..482193e975d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-anon1.C @@ -0,0 +1,18 @@ +// DR 1612 +// { dg-require-effective-target c++11 } + +int main() { + static int result; + struct A { int x; }; + struct B { int y; }; + union { + A a; B b; + }; + a.x = 1; + [=]() mutable { + a.x = 2; // { dg-error "anonymous union" } + result = b.y; // { dg-error "anonymous union" } + }(); + if (result == 1) return 0; + throw 0; +}