From patchwork Sat Jul 30 06:20:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 107479 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 5B74CB6F6B for ; Sat, 30 Jul 2011 16:20:28 +1000 (EST) Received: (qmail 24438 invoked by alias); 30 Jul 2011 06:20:25 -0000 Received: (qmail 24423 invoked by uid 22791); 30 Jul 2011 06:20:24 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 30 Jul 2011 06:20:02 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6U6K2mN007092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 30 Jul 2011 02:20:02 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6U6K1BQ026050 for ; Sat, 30 Jul 2011 02:20:01 -0400 Received: from [0.0.0.0] (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p6U6K0Hd012371 for ; Sat, 30 Jul 2011 02:20:01 -0400 Message-ID: <4E33A290.9010505@redhat.com> Date: Fri, 29 Jul 2011 23:20:00 -0700 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110719 Thunderbird/5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49867 (ICE with case label in lambda) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org When we enter a local class, including a lambda, we are no longer in the scope of any enclosing loops or switches, and we should adjust the parser state accordingly. Tested x86_64-pc-linux-gnu, applying to trunk. commit 72900624cbb7b7ded0deb615c5175fe34531914a Author: Jason Merrill Date: Fri Jul 29 15:22:27 2011 -0700 PR c++/49867 * parser.c (cp_parser_lambda_expression): Also clear in_statement and in_switch_statement_p. (cp_parser_class_specifier): Likewise. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b7410d5..3828ca9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7437,8 +7437,12 @@ cp_parser_lambda_expression (cp_parser* parser) /* Inside the class, surrounding template-parameter-lists do not apply. */ unsigned int saved_num_template_parameter_lists = parser->num_template_parameter_lists; + unsigned char in_statement = parser->in_statement; + bool in_switch_statement_p = parser->in_switch_statement_p; parser->num_template_parameter_lists = 0; + parser->in_statement = 0; + parser->in_switch_statement_p = false; /* By virtue of defining a local class, a lambda expression has access to the private variables of enclosing classes. */ @@ -7471,6 +7475,8 @@ cp_parser_lambda_expression (cp_parser* parser) type = finish_struct (type, /*attributes=*/NULL_TREE); parser->num_template_parameter_lists = saved_num_template_parameter_lists; + parser->in_statement = in_statement; + parser->in_switch_statement_p = in_switch_statement_p; } pop_deferring_access_checks (); @@ -17007,6 +17013,8 @@ cp_parser_class_specifier_1 (cp_parser* parser) bool nested_name_specifier_p; unsigned saved_num_template_parameter_lists; bool saved_in_function_body; + unsigned char in_statement; + bool in_switch_statement_p; bool saved_in_unbraced_linkage_specification_p; tree old_scope = NULL_TREE; tree scope = NULL_TREE; @@ -17060,6 +17068,12 @@ cp_parser_class_specifier_1 (cp_parser* parser) /* We are not in a function body. */ saved_in_function_body = parser->in_function_body; parser->in_function_body = false; + /* Or in a loop. */ + in_statement = parser->in_statement; + parser->in_statement = 0; + /* Or in a switch. */ + in_switch_statement_p = parser->in_switch_statement_p; + parser->in_switch_statement_p = false; /* We are not immediately inside an extern "lang" block. */ saved_in_unbraced_linkage_specification_p = parser->in_unbraced_linkage_specification_p; @@ -17254,6 +17268,8 @@ cp_parser_class_specifier_1 (cp_parser* parser) pop_deferring_access_checks (); /* Restore saved state. */ + parser->in_switch_statement_p = in_switch_statement_p; + parser->in_statement = in_statement; parser->in_function_body = saved_in_function_body; parser->num_template_parameter_lists = saved_num_template_parameter_lists; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C new file mode 100644 index 0000000..c306771 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C @@ -0,0 +1,26 @@ +// PR c++/49867 +// { dg-options -std=c++0x } + +int +main () +{ + void (*l)(); + while (true) + { + switch (3) + { + struct A { + void f() + { + case 4: // { dg-error "case" } + break; // { dg-error "break" } + } + }; + l = []() + { + case 3: // { dg-error "case" } + break; // { dg-error "break" } + }; + } + } +}