From patchwork Thu Dec 9 03:10:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 74843 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 93F62B710D for ; Thu, 9 Dec 2010 14:10:25 +1100 (EST) Received: (qmail 12876 invoked by alias); 9 Dec 2010 03:10:22 -0000 Received: (qmail 12856 invoked by uid 22791); 9 Dec 2010 03:10:20 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Dec 2010 03:10:15 +0000 Received: (qmail 20845 invoked from network); 9 Dec 2010 03:10:13 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 9 Dec 2010 03:10:13 -0000 Date: Wed, 8 Dec 2010 22:10:09 -0500 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: [PATCH,c++] fix PR 46852, ICE in semicolon recovery code Message-ID: <20101209031007.GF25904@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 The patch below fixes PR 46852: before we inspect the type that we just parsed for a class/struct/union definition, we should make sure that it's actually a type and not something bogus from a parse error. Tested on x86_64-unknown-linux-gnu. OK to commit? -Nathan gcc/cp/ PR c++/46852 * parser.c (cp_parser_class_specifier): Check for TYPE_P. gcc/testsuite/ PR c++/46852 * g++.dg/pr46852.C: New test. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ab533f4..089361a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -16937,7 +16937,9 @@ cp_parser_class_specifier (cp_parser* parser) break; } - if (want_semicolon) + /* If we don't have a type, then something is very wrong and we + shouldn't try to do anything clever. */ + if (TYPE_P (type) && want_semicolon) { cp_token_position prev = cp_lexer_previous_token_position (parser->lexer); diff --git a/gcc/testsuite/g++.dg/pr46852.C b/gcc/testsuite/g++.dg/pr46852.C new file mode 100644 index 0000000..2c9d8dd --- /dev/null +++ b/gcc/testsuite/g++.dg/pr46852.C @@ -0,0 +1,7 @@ +// PR c++/46852 +// { dg-do compile } + +template +< +class +{ // { dg-error "" }