From patchwork Tue Nov 19 23:46:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1197691 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514085-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ogshR6f/"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="LI1VcBaq"; 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 47HjCl6WRDz9s7T for ; Wed, 20 Nov 2019 10:46:58 +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:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=Llp yfnjYm3gDeS8ChGTjQkXjehi8toSNOkJHgARBycHroiFSv8x9FSmweGGbKOiOxg9 aL8vqswG4tX+GJhJMSzpcesIRDkzF7N4fjZRugkXZXZhiXpnMfxZti4TFhVv2e7E It+yGzKZKEYjZeD+oLZPPIfKCHsAsBBMFkD1Z9Sc= 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:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=EBh5K+Uf7 L4J8d0PCL7l2qLN2Sk=; b=ogshR6f/94XNzgsQriTFalwscHx7TQn3ptzTznKXy ebHqOVgkp2cIsDZvrfidvDWa4J3Mx8wdkjNdxynlDW7tf/d+g6qhhWY2n4IbuaqK 3GfwLIDKsWFSg16H9SXyWqmhMNmTDJp7UZSGn4k0Ujik5l73GDahPvJTjtVN/KNx 44= Received: (qmail 110158 invoked by alias); 19 Nov 2019 23:46:51 -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 110148 invoked by uid 89); 19 Nov 2019 23:46:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Nov 2019 23:46:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574207207; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+odxfm5cXJVc4aVpgJCpquSD/CAYJObt49jDAKkMG4A=; b=LI1VcBaq1bpI3lAznTwCuiPDrP5LTqLfNNYmmHnNUyBkH1mY7vLbp6E6BORVN9GG/rLWCY t7hSUvtbas+MBXkNJ+SiYYcitmSxdna6Lykt8qc0Wm+7Bx/34fBWyr7RSv6rzoXOfkl7JT 9b1IDmwmBsAUICPX2zSEtuIffRllzBY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-8dVC-SIsMI2r3Wwho0yE1A-1; Tue, 19 Nov 2019 18:46:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C58B71852E20 for ; Tue, 19 Nov 2019 23:46:45 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 609634DA75; Tue, 19 Nov 2019 23:46:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id xAJNkhm1029799; Wed, 20 Nov 2019 00:46:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xAJNkg4R029798; Wed, 20 Nov 2019 00:46:42 +0100 Date: Wed, 20 Nov 2019 00:46:42 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix up lambda decl specifier parsing ICE (PR c++/90842) Message-ID: <20191119234642.GQ4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! In lambdas, the only valid decl specifiers are mutable, constexpr or consteval. For various other simple specifiers it is fine to parse them and reject afterwards if the parsing is simple consuming of a single token and setting some flags, but as the testcase shows, especially allowing type specifiers, including new type definitions in there can cause ICEs. The following patch punts for the cases where the parsing isn't that simple, which I think is concept, typedef (there we e.g. commit tentative parsing) or the type specifiers. Bootstrapped/regtested on x86_64-linux and i686-linux, ok of trunk? 2019-11-19 Jakub Jelinek PR c++/90842 * parser.c (cp_parser_decl_specifier_seq): For concept, typedef or type specifier with CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR don't try to parse them at all. * g++.dg/cpp1y/lambda-generic-90842.C: New test. * g++.dg/cpp0x/lambda/lambda-86550.C: Adjust expected diagnostics. Jakub --- gcc/cp/parser.c.jj 2019-11-14 09:13:24.356104252 +0100 +++ gcc/cp/parser.c 2019-11-19 17:47:24.776014270 +0100 @@ -14094,6 +14094,12 @@ cp_parser_decl_specifier_seq (cp_parser* break; case RID_CONCEPT: + if (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR) + { + found_decl_spec = false; + break; + } + ds = ds_concept; cp_lexer_consume_token (parser->lexer); @@ -14136,6 +14142,12 @@ cp_parser_decl_specifier_seq (cp_parser* /* decl-specifier: typedef */ case RID_TYPEDEF: + if (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR) + { + found_decl_spec = false; + break; + } + ds = ds_typedef; /* Consume the token. */ cp_lexer_consume_token (parser->lexer); @@ -14229,7 +14241,9 @@ cp_parser_decl_specifier_seq (cp_parser* /* If we don't have a DECL_SPEC yet, then we must be looking at a type-specifier. */ - if (!found_decl_spec && !constructor_p) + if (!found_decl_spec + && !constructor_p + && (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR) == 0) { int decl_spec_declares_class_or_enum; bool is_cv_qualifier; @@ -14288,9 +14302,6 @@ cp_parser_decl_specifier_seq (cp_parser* found_decl_spec = true; if (!is_cv_qualifier) decl_specs->any_type_specifiers_p = true; - - if ((flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR) != 0) - error_at (token->location, "type-specifier invalid in lambda"); } } --- gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C.jj 2019-11-19 17:53:37.682440002 +0100 +++ gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C 2019-11-19 17:53:01.815976144 +0100 @@ -0,0 +1,4 @@ +// PR c++/90842 +// { dg-do compile { target c++14 } } + +auto a = [](auto x) struct C { void foo (); } {}; // { dg-error "expected" } --- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-86550.C.jj 2018-07-18 23:01:22.824082949 +0200 +++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-86550.C 2019-11-19 17:54:26.978703112 +0100 @@ -4,6 +4,6 @@ void foo () { - auto a = []() bool {}; // { dg-error "type-specifier invalid in lambda" } - auto b = []() bool bool bool bool int {}; // { dg-error "type-specifier invalid in lambda" } + auto a = []() bool {}; // { dg-error "expected" } + auto b = []() bool bool bool bool int {}; // { dg-error "expected" } }