Fix PR c++/70218 (illegal access to private field succeeds)
authorPatrick Palka <ppalka@gcc.gnu.org>
Fri, 18 Mar 2016 01:23:26 +0000 (01:23 +0000)
committerPatrick Palka <ppalka@gcc.gnu.org>
Fri, 18 Mar 2016 01:23:26 +0000 (01:23 +0000)
gcc/cp/ChangeLog:

PR c++/70218
* parser.c (cp_parser_lambda_expression): Move call to
pop_deferring_access_checks ahead of the call to
cp_parser_end_tentative_firewall.

gcc/testsuite/ChangeLog:

PR c++/70218
* g++.dg/cpp0x/lambda/lambda-70218.C: New test.

From-SVN: r234316

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

index 15ca9a48111cb74af2db453f71a5b5191dfb24de..764122a30637a26aba8ff29f00da5a4fc1855099 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-18  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70218
+       * parser.c (cp_parser_lambda_expression): Move call to
+       pop_deferring_access_checks ahead of the call to
+       cp_parser_end_tentative_firewall.
+
 2016-03-17  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/70144
index 8ba4ffecdc2b88f1647ea0bad449481aa6c9fb07..7e13c6e74f676e95ff7ff6acf314bbc1739a8d3e 100644 (file)
@@ -9781,8 +9781,6 @@ cp_parser_lambda_expression (cp_parser* parser)
        = auto_is_implicit_function_template_parm_p;
   }
 
-  pop_deferring_access_checks ();
-
   /* This field is only used during parsing of the lambda.  */
   LAMBDA_EXPR_THIS_CAPTURE (lambda_expr) = NULL_TREE;
 
@@ -9798,6 +9796,8 @@ cp_parser_lambda_expression (cp_parser* parser)
 
   cp_parser_end_tentative_firewall (parser, start, lambda_expr);
 
+  pop_deferring_access_checks ();
+
   return lambda_expr;
 }
 
index 4fa5519075a76e8f884eebc46c8ba94f397bd7c6..5f792eee8037e06e48d7028412bc66863cadbf87 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-18  Patrick Palka  <ppalka@gcc.gnu.org>
+
+       PR c++/70218
+       * g++.dg/cpp0x/lambda/lambda-70218.C: New test.
+
 2016-03-17  Marek Polacek  <polacek@redhat.com>
 
        PR c/69407
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-70218.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-70218.C
new file mode 100644 (file)
index 0000000..ae8cc2f
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/70218
+// { dg-do compile { target c++11 } }
+
+struct X {
+private:
+   int i;
+};
+
+struct Y {
+  Y (int) { }
+};
+
+void
+foo ()
+{
+  Y ([] { X x; x.i = 3; return 0; } ()); // { dg-error "private" }
+}