From patchwork Thu Apr 16 23:33:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1271938 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nbdrkkyB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 493Fsc1X97z9sQx for ; Fri, 17 Apr 2020 09:33:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D1D5385DC00; Thu, 16 Apr 2020 23:33:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D1D5385DC00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587080014; bh=q1+C7wmA4y7HmXnmlME0kZ66q4TWg91BEThuc0xlLlQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nbdrkkyBCv6A25jGEb7//FP/DrfmTX5FxDKAoZtMCYjITTGo9xnIQig+sBHaLZND+ 5IBYVFxFC6+yyl/65w6kPHrLCz2aQkcEUnStb9mjS3DFs1FdJfgdznLcU8ibusgAnn ac5wuWtqoBuc9Qm8x4y1paoscqXmesxG4dsUmz+I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 1D027385C426 for ; Thu, 16 Apr 2020 23:33:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D027385C426 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-321-lyrG-anKOpmY4VSp7VgDhg-1; Thu, 16 Apr 2020 19:33:30 -0400 X-MC-Unique: lyrG-anKOpmY4VSp7VgDhg-1 Received: by mail-qv1-f71.google.com with SMTP id bm3so203170qvb.0 for ; Thu, 16 Apr 2020 16:33:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=z5mPp5GlksJ1vRqOMdPf9q27IJaXGNXZ3tOG7JlyAjc=; b=IkeW4bncEs3smNx+dfJ2+jdPxeDdPPf3EFFpYhAkJSkqCIRO9LgZs4XvW9vNpvF49/ H6AxsiHio/dQ+WkbZYBuN/ZNu/RVpWmU0Srh58fl5UjsRoCo1dlA5HR9+fF5ChQN3CaY WZexgOCByFYYtHTUir0+9qdG8Wia9/OcQhr7JAQm5Z+DnkWk0psK+xB+DLdT8z3p9EU2 AYbuSYHOzCe/dVa0rxohv9nWK0SIORWzFQwz0dQMoiMHm8KRu211pZHDYZ7NHqrU5JN5 QrECD/9o5Zphy9hCCaswv/l+spXvozEk9hBU4Pbqvcy3ASKbzbIv8jEr9cDnYceRb5zA xNdw== X-Gm-Message-State: AGi0PuZNsliXoau7L5t8S5r+MYmQCSH8ZhhqO5H8lj+LwIeHaEBaaCQA fyVLUzMLQbSPzslxO+6cVYQVIP6YNGtu7snvVjihdR2p9FXjaVz2Q2jl6UBmRJICR0MYC4Taf77 Q6PkonKptRtRbT0ZBfg== X-Received: by 2002:ac8:1788:: with SMTP id o8mr214484qtj.15.1587080009555; Thu, 16 Apr 2020 16:33:29 -0700 (PDT) X-Google-Smtp-Source: APiQypI+UDlxCRP6shve4iW/oIvgq9k2qz7z6F1rxRphSJ2LCxixKMXJC4IPLl1m/uDby77cPH5NBQ== X-Received: by 2002:ac8:1788:: with SMTP id o8mr214460qtj.15.1587080009309; Thu, 16 Apr 2020 16:33:29 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id y188sm12835958qkd.35.2020.04.16.16.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 16:33:28 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Hard error with tentative parse of declaration [PR88754] Date: Thu, 16 Apr 2020 19:33:19 -0400 Message-Id: <20200416233319.3394053-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.1.107.gefe3874640 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In the testcase for this PR, we try to parse the statement A(value<0>()); first tentatively as a declaration (with a parenthesized declarator), and during this tentative parse we end up issuing a hard error from cp_parser_check_template_parameters about its invalidness as a declaration. Rather than issuing a hard error, it seems we should instead simulate an error since we're parsing tentatively. This would then allow cp_parser_statement to recover and successfully parse the statement as an expression-statement instead. Passes 'make check-c++', does this look OK to commit after bootstrap/regtesting? gcc/cp/ChangeLog: PR c++/88754 * parser. (cp_parser_check_template_parameters): Before issiung a hard error, first try simulating an error instead. gcc/testsuite/ChangeLog: PR c++/88754 * g++.dg/parse/ambig10.C: New test. --- gcc/cp/parser.c | 4 ++++ gcc/testsuite/g++.dg/parse/ambig10.C | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/ambig10.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index e037e7d8c8e..47e3f2bbd3d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28531,6 +28531,10 @@ cp_parser_check_template_parameters (cp_parser* parser, if (!template_id_p && parser->num_template_parameter_lists == num_templates + 1) return true; + + if (cp_parser_simulate_error (parser)) + return false; + /* If there are more template classes than parameter lists, we have something like: diff --git a/gcc/testsuite/g++.dg/parse/ambig10.C b/gcc/testsuite/g++.dg/parse/ambig10.C new file mode 100644 index 00000000000..42b04b16923 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/ambig10.C @@ -0,0 +1,20 @@ +// PR c++/88754 +// { dg-do compile } + +struct A +{ + A(int); + void foo(); +}; + +template int value() { return N; } + +void bar() +{ + A(value<0>()).foo(); + A(value<0>()); + (A(value<0>())).foo(); + + A value<0>; // { dg-error "invalid declaration" } + A value<0>(); // { dg-error "invalid declaration" } +}