Core 1612
authorJason Merrill <jason@redhat.com>
Mon, 22 Apr 2013 18:52:50 +0000 (14:52 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 22 Apr 2013 18:52:50 +0000 (14:52 -0400)
Core 1612
* semantics.c (finish_id_expression): Reject capture of anonymous
union member.

From-SVN: r198153

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

index 0dada14784a7ec4963acd2446108a8c6f3416687..b8c4727d6aebbe9ef14ec051189cd94e06554c90 100644 (file)
@@ -1,5 +1,9 @@
 2013-04-22  Jason Merrill  <jason@redhat.com>
 
+       Core 1612
+       * semantics.c (finish_id_expression): Reject capture of anonymous
+       union member.
+
        Core 1609
        * decl2.c (check_default_args): Check for pack expansion.
 
index 2784d797bdb06631ee533601f31c7fcfbc0bc9a5..391dc1e558a81e6ba6eb5faa52172c3f16b346f9 100644 (file)
@@ -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 (file)
index 0000000..482193e
--- /dev/null
@@ -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;
+}