From patchwork Thu Dec 8 16:42:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 61703 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 3735638B136E for ; Thu, 8 Dec 2022 16:43:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3735638B136E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670517787; bh=fGqZH5HcvhrOh4OzILofWNcGlwNhS5DHRqlrnmi1UPY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=E74Y37YWLVqJmzhdXQGPi/3zFJ2Q9g6FT3FUYod8N1GH5Ddgad8YnoqmAjiL58uN7 juy+Kj5sZ8sGlKvRtjNRpr8MXVZkL3KTOVzzCw2mggN3Q5Fu5Bw7xDFDggTkRSgZA6 cJtau6DdDXHfUs1ZEMu8+Ds/HfylslpmlWivc+wA= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 49C2B38B136B for ; Thu, 8 Dec 2022 16:42:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 49C2B38B136B Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-403-z3SJmKZPO3y03a1RjvLSzw-1; Thu, 08 Dec 2022 11:42:34 -0500 X-MC-Unique: z3SJmKZPO3y03a1RjvLSzw-1 Received: by mail-qt1-f199.google.com with SMTP id w27-20020a05622a191b00b003a56c0e1cd0so1851359qtc.4 for ; Thu, 08 Dec 2022 08:42:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fGqZH5HcvhrOh4OzILofWNcGlwNhS5DHRqlrnmi1UPY=; b=YcQqfO92sQBRVBORCQ0sZgRm0mCQgDc9007W0uQWaDQrWNBHWzj6b31qSKSFRYR95Q 4mNsZ+ayt8a+xAh97MzF4AdSEbkBscYjg3dTm3ZO7Dxxq+CmILAGxU8w9SlJmE+lImY2 hRkbxhi29x5+R0m5Dboi02q1avdZVXS1dtYMtAOyuP9jUScSiLICV8xt9Nov2NukT4Ld CxuZcS1ymrLU/Ioq6za9oLcBznzyPI9H+REpMF3bpW5TGVek4Clwmt7iU+qx3R/EWqnF DbpS3Ep003CDgFq+VEbTFmtf8GeZWli18wX/Qb6Uf/D0uyAPmoE4a42QzoiRR50siqY7 czvw== X-Gm-Message-State: ANoB5pnOypHqRxg0KDjdXn9TO26FkSRk6jeSKSeRL46TrpQOzjWl1XdE 8uBQGFMYfIsskJo4j8L+cQKwFhppGx8gbrFaxM2dMUS3pAI6GEZgjr4owZ6uMu+bYhPD16lRI4K Wd7GUGIRKq1o1gLSXK3pvbQPpJBdfODRz1kbvsiOnQ621FXZbaCNow8NcXN7zBczrkA4= X-Received: by 2002:ae9:f111:0:b0:6fc:94f7:6cf6 with SMTP id k17-20020ae9f111000000b006fc94f76cf6mr34102831qkg.517.1670517753886; Thu, 08 Dec 2022 08:42:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf6OYxum8x/7xeEKbBfAL1jV9G9OtXXl5/jnfBefHdCEsaD7aIeuKc2fL/FDe8HqPX8PkhyG1g== X-Received: by 2002:ae9:f111:0:b0:6fc:94f7:6cf6 with SMTP id k17-20020ae9f111000000b006fc94f76cf6mr34102820qkg.517.1670517753531; Thu, 08 Dec 2022 08:42:33 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id dc53-20020a05620a523500b006fefa5f7fcesm2597877qkb.10.2022.12.08.08.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 08:42:33 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: class-scope qualified constrained auto [PR107188] Date: Thu, 8 Dec 2022 11:42:30 -0500 Message-Id: <20221208164230.2208644-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 parsing the class-scope auto constrained by a qualified concept-id, we first tentatively parse the overall member-declaration as a deprecated access-declaration, during which we parse C as a standalone TEMPLATE_ID_EXPR (not part of the auto) and end up emitting the bogus error concepts-placeholder11.C:9:6: error: wrong number of template arguments (1, should be 2) 9 | N::C auto f() { return 0; } | ^~~~~~ concepts-placeholder11.C:5:34: note: provided for ‘template concept N::C’ 5 | template concept C = true; | ^ from build_concept_id called from cp_parser_template_id_expr. We could fix this by adding a complain parameter to build_concept_id and passing tf_none when parsing tentatively. However, it seems we can fix this in a more general way that might benefit non-concepts code: when tentatively parsing an access-declaration, abort the parse early if the qualifying scope isn't possibly a class type, so that we avoid parsing C as a TEMPLATE_ID_EXPR in the first place. This patch takes this latter approach. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/107188 gcc/cp/ChangeLog: * parser.cc (cp_parser_using_declaration): Abort the tentative parse early if the scope of an access-declaration isn't possibly a class type. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-placeholder11.C: New test. --- gcc/cp/parser.cc | 5 +++++ gcc/testsuite/g++.dg/cpp2a/concepts-placeholder11.C | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-placeholder11.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index e8a50904243..ccacf6d7dd0 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -21670,6 +21670,11 @@ cp_parser_using_declaration (cp_parser* parser, cp_warn_deprecated_use_scopes (qscope); + if (access_declaration_p && !MAYBE_CLASS_TYPE_P (qscope)) + /* If the qualifying scope of an access-declaration isn't possibly + a class type then it must be invalid. */ + cp_parser_simulate_error (parser); + if (access_declaration_p && cp_parser_error_occurred (parser)) /* Something has already gone wrong; there's no need to parse further. Since an error has occurred, the return value of diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder11.C b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder11.C new file mode 100644 index 00000000000..61eef743bae --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-placeholder11.C @@ -0,0 +1,10 @@ +// PR c++/107188 +// { dg-do compile { target c++20 } } + +namespace N { + template concept C = true; +} + +struct X { + N::C auto f() { return 0; } +};