From patchwork Wed Feb 21 10:36:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 876020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-473658-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TP7e14+A"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zmYnJ4V45z9ry4 for ; Wed, 21 Feb 2018 21:36:35 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=NbftcwRo+SQlkb0kTTuFWd3CpMk63HTls2BXQa9hMJ7/NgjQfdbkF YkouwB/YEt6VwCsD/2xREQu1SWavGvE+34MY7xJ7rhO3C/kx569Lwef/mvxolw45 qon2QIcZnKHo9NejPsRf0ZdWiNUNK1L2/YbNFG740OqWg1Yv5Z9MNA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=rvpaBkNCFnJw3J3bo2ttpCEQRag=; b=TP7e14+AqER0hKB8ZPg8 WPP9/OQK1u6rCf3/nDOB++EXfHazCeUlpKk6hXTQgEz7JdePT0vADYvt7vVcvXRi 80E9wH81UiwY5S/rBJUzPHefhUL9vJjg4lcXgSb0Lj02+1G5eoS0WtURo8wV9EVt 1ftTJhoBpAczrKjfLVlI18s= Received: (qmail 45986 invoked by alias); 21 Feb 2018 10:36:29 -0000 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 Received: (qmail 45970 invoked by uid 89); 21 Feb 2018 10:36:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Feb 2018 10:36:27 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B080356E2 for ; Wed, 21 Feb 2018 10:36:26 +0000 (UTC) Received: from redhat.com (ovpn-204-84.brq.redhat.com [10.40.204.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5825D5EDE4; Wed, 21 Feb 2018 10:36:25 +0000 (UTC) Date: Wed, 21 Feb 2018 11:36:07 +0100 From: Marek Polacek To: Jason Merrill , GCC Patches Subject: C++ PATCH to fix ICE with invalid cast (PR c++/84493) Message-ID: <20180221103607.GK2629@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Here we can prevent a crash on invalid by using require_open where '{' is expected. require_open uses cp_parser_require whereas consume_open has an assert: gcc_assert (tok->type == traits_t::open_token_type); which triggers here. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-02-21 Marek Polacek PR c++/84493 * parser.c (cp_parser_braced_list): Use require_open instead of consume_open. * g++.dg/parse/error59.C: New test. Marek diff --git gcc/cp/parser.c gcc/cp/parser.c index 2bb0d2da5fe..4fa546a086c 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -21925,7 +21925,7 @@ cp_parser_braced_list (cp_parser* parser, bool* non_constant_p) /* Consume the `{' token. */ matching_braces braces; - braces.consume_open (parser); + braces.require_open (parser); /* Create a CONSTRUCTOR to represent the braced-initializer. */ initializer = make_node (CONSTRUCTOR); /* If it's not a `}', then there is a non-trivial initializer. */ diff --git gcc/testsuite/g++.dg/parse/error59.C gcc/testsuite/g++.dg/parse/error59.C index e69de29bb2d..2c44e210366 100644 --- gcc/testsuite/g++.dg/parse/error59.C +++ gcc/testsuite/g++.dg/parse/error59.C @@ -0,0 +1,6 @@ +// PR c++/84493 + +void foo() +{ + (struct {}x){}; // { dg-error "" } +}