From patchwork Mon Nov 8 15:35:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 47216 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEC6E385800C for ; Mon, 8 Nov 2021 15:36:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEC6E385800C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636385792; bh=0pWH3JDO47hBvOUdEviATC4EwwADZY9BDdQNC1B6jsQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DaaYbNGNzC+gPpT8vlqpYbHzUHsHe4R/6+YHJyjkOIxjamckdTWvPIv2NEdOH/3wh bpl3ybxRbPcsPaov4CV9cFzVyMnnQ2QkclEJkHatYKHmYaJvW4U2l8uBvkaVQCTvXh J0bQcRil3esgx21J5LlFkbbb2rl0GPhO/Sc7NCD4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 59E103858D3C for ; Mon, 8 Nov 2021 15:36:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59E103858D3C Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-9-qnXfkGND-SDftdF22fVA-1; Mon, 08 Nov 2021 10:36:00 -0500 X-MC-Unique: 9-qnXfkGND-SDftdF22fVA-1 Received: by mail-qt1-f198.google.com with SMTP id 100-20020aed30ed000000b002a6b3dc6465so12105265qtf.13 for ; Mon, 08 Nov 2021 07:36:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0pWH3JDO47hBvOUdEviATC4EwwADZY9BDdQNC1B6jsQ=; b=xdnqzPlSbQ0N4EfwgfmXK3nOPjxIrE4sv8CnO+tFA/XFiAQNkhlb8HHXshCIYKtXgz 2XcLZ7ywnzlgbxN5Gvtz4s03ITTX1uLLj95/F9Hk8wHIcbHRYRtJyOhtCSJ8d6gO/KdB Ft3hOEwkjT6N9lN51yRo+9HV9fNLQfyoFlJmNrNg6vNHXCW1O5gYqcyLAxXAKKabrPLc gr6c/0/H68aDkZNFndT1CU4PQWSpBIr1jBiMIXkhuV6Qs9wwZ9nLJwIMM3q18g5nJjzh UcGA3Jrw+GWT4KQns0OHuWhsLIvtbljWARxnCJGj+hU7y/4ECfByxOmK8WQxDF1sUiYk FdXw== X-Gm-Message-State: AOAM5320fftY995YMRZRxIp10GoHpW8kXVdhG7Er+75J5oPpo/bQLw9Y PbrzQS8FRE/YeO5Gw9Qdvf3LYPvSA8JrCIyDObw4Q3wD+RrKLx3Lzrt/nWoGSE/YjklBrLwYC67 aGDFBqqQNwJdFDWbcK0pbEoLm07mafOLJQmN9RYO61HixrKtFJ7yOOg7lPGYIUV+vfOA= X-Received: by 2002:a05:622a:14a:: with SMTP id v10mr439880qtw.36.1636385759762; Mon, 08 Nov 2021 07:35:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzT16tTskg2X4PkN7khv4hwQnjQPuBUDdlACOUAU40IOnXOd8+O8MJSVCmCLT1qQzSlSKVPVQ== X-Received: by 2002:a05:622a:14a:: with SMTP id v10mr439847qtw.36.1636385759469; Mon, 08 Nov 2021 07:35:59 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id f34sm3037535qtb.7.2021.11.08.07.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 07:35:59 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: bogus error w/ variadic concept-id as if cond [PR98394] Date: Mon, 8 Nov 2021 10:35:50 -0500 Message-Id: <20211108153550.3290787-1-ppalka@redhat.com> X-Mailer: git-send-email 2.34.0.rc1.14.g88d915a634 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Here when tentatively parsing the if condition as a declaration, we try to treat C<1> as the start of a constrained placeholder type, which we quickly reject because C doesn't accept a type as its first argument. But since we're parsing tentatively, we shouldn't emit an error in this case. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/11? PR c++/98394 gcc/cp/ChangeLog: * parser.c (cp_parser_placeholder_type_specifier): Don't emit a "does not constrain a type" error when parsing tentatively. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-pr98394.C: New test. --- gcc/cp/parser.c | 7 +++++-- gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4c2075742d6..f1498e28da4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19909,8 +19909,11 @@ cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc, if (!flag_concepts_ts || !processing_template_parmlist) { - error_at (loc, "%qE does not constrain a type", DECL_NAME (con)); - inform (DECL_SOURCE_LOCATION (con), "concept defined here"); + if (!tentative) + { + error_at (loc, "%qE does not constrain a type", DECL_NAME (con)); + inform (DECL_SOURCE_LOCATION (con), "concept defined here"); + } return error_mark_node; } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C new file mode 100644 index 00000000000..c8407cdf7cd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C @@ -0,0 +1,14 @@ +// PR c++/98394 +// { dg-do compile { target c++20 } } + +template +concept C = true; + +template +concept D = true; + +int main() { + if (C<1>); // { dg-bogus "does not constrain a type" } + if (D<1>); // { dg-error "wrong number of template arguments" } + // { dg-bogus "does not constrain a type" "" { target *-*-* } .-1 } +}