From patchwork Mon Nov 28 20:52:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1709939 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=UcuawyXe; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NLd3473CWz23nB for ; Tue, 29 Nov 2022 07:53:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAED7385C301 for ; Mon, 28 Nov 2022 20:53:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAED7385C301 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669668783; bh=fo1s7KjMS7zUhBlwfEZbJkPzT90+PnZ5XfFCPrp1DLE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UcuawyXedfZid0DwqrQFihpJQqUWD8L75pi5SEYmaXu+tJHzPPNEgF9AA+q/rgUZ6 f4IUF2ZvTZT427M4RJW/wHL1vDnNyhDFKoOwiSRqtqkVS1mAHN5QHKJd0TKX+lIrFx Pb4ggOv1BDIlpERq2KT+oBJOZzAYNDRO87kQtyXc= 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 497323854574 for ; Mon, 28 Nov 2022 20:52:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 497323854574 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-436-Yoy5Bg-KMUSSAhSxYyOuzA-1; Mon, 28 Nov 2022 15:52:41 -0500 X-MC-Unique: Yoy5Bg-KMUSSAhSxYyOuzA-1 Received: by mail-qv1-f70.google.com with SMTP id q17-20020a056214019100b004b1d3c9f3acso15433511qvr.0 for ; Mon, 28 Nov 2022 12:52:41 -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:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fo1s7KjMS7zUhBlwfEZbJkPzT90+PnZ5XfFCPrp1DLE=; b=hX0NngJ4uIX+Thl4nVMCaVmaoz4t6XEmzFJ7T1TDQlPk7oUa5qX1o2FlJWhc0uPhUi 9RaSj5emBFTECEWWCaxvmSo8dpsmaRin1ZQZYCbEHYzXg22drRGBT9JILj25GTCVZOLE 3ZfZJa10lAGHmLgq4Cwu8i8wygtMG9iAGS/AAC2XumD5SPCenlz19r+0UtOAFdPq3K5q R6Zn/2JZwzIUehtgZEU/c6RiSl+iO02xvWjpzcZiOb5uEQXJ11LqHyjKoWzDlxyVQXP7 oV3Yv3wB1MGGeyQGylHc3JjuwgTw3L4urKH+9D++KPD3ZAjOtPzEmKiezmypXc6D2967 ADAA== X-Gm-Message-State: ANoB5pmEsB2gXfaRIGz/ZNp1vfLx3qlnZzn9IJgSRfJo7cAOhjYgUv8f hcmMa/fHzek6giyZkg/RYlJw6mQubYZUgsIatQGpZg1aXq+MjNTBBkkESsbYt3HvY1ppXdEDfpO 9P6bcYGq2HL3xL6dQtFWlkaleVfWAO1q/hVIQ4F6lpppd1/H9f/xra35MP9J8gT2WYQ== X-Received: by 2002:ac8:67c5:0:b0:3a4:f665:7791 with SMTP id r5-20020ac867c5000000b003a4f6657791mr50621962qtp.380.1669668760983; Mon, 28 Nov 2022 12:52:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wjE23w4ORJtGP+MSHUgE0C3rppqhrjoowUIhHonEpd6BXMK6DHjTDTd0EuR9HQf+cBvw2zA== X-Received: by 2002:ac8:67c5:0:b0:3a4:f665:7791 with SMTP id r5-20020ac867c5000000b003a4f6657791mr50621935qtp.380.1669668760601; Mon, 28 Nov 2022 12:52:40 -0800 (PST) Received: from jason.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id w30-20020a05620a0e9e00b006faaf6dc55asm8929446qkm.22.2022.11.28.12.52.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 12:52:40 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: simple-requirement starting with 'typename' [PR101733] Date: Mon, 28 Nov 2022 15:52:36 -0500 Message-Id: <20221128205236.541407-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Usually a requirement starting with 'typename' is a type-requirement, but it might be a simple-requirement such as a functional cast to a typename-type. PR c++/101733 gcc/cp/ChangeLog: * parser.cc (cp_parser_requirement): Parse tentatively for the 'typename' case. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires32.C: New test. --- gcc/cp/parser.cc | 15 ++++++++++++++- gcc/testsuite/g++.dg/cpp2a/concepts-requires32.C | 11 +++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires32.C base-commit: 47d81b1b89d615cea27307c713a4afe591e1cd2d prerequisite-patch-id: 275d90e1bd8b940c1cca2840bc38dc4fafa0797b diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 82459b7683a..a13fbe41309 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -30737,7 +30737,20 @@ cp_parser_requirement (cp_parser *parser) if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) return cp_parser_compound_requirement (parser); else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME)) - return cp_parser_type_requirement (parser); + { + /* It's probably a type-requirement. */ + cp_parser_parse_tentatively (parser); + tree req = cp_parser_type_requirement (parser); + if (cp_parser_parse_definitely (parser)) + return req; + /* No, maybe it's something like typename T::type(); */ + cp_parser_parse_tentatively (parser); + req = cp_parser_simple_requirement (parser); + if (cp_parser_parse_definitely (parser)) + return req; + /* Non-tentative for the error. */ + return cp_parser_type_requirement (parser); + } else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_REQUIRES)) return cp_parser_nested_requirement (parser); else diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires32.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires32.C new file mode 100644 index 00000000000..117b8920787 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires32.C @@ -0,0 +1,11 @@ +// PR c++/101733 +// { dg-do compile { target c++20 } } + +template +requires requires { + typename T::type; + (typename T::type()); // (1) + T::type(); // (2) + typename T::type(); // (3) +} +void f(T) { }