From patchwork Wed Jun 12 18:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1947065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dDJD1lCc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vzv6X4ZQ1z20Pb for ; Thu, 13 Jun 2024 04:23:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8D413882061 for ; Wed, 12 Jun 2024 18:22:58 +0000 (GMT) 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 1B02F3870899 for ; Wed, 12 Jun 2024 18:22:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B02F3870899 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B02F3870899 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718216561; cv=none; b=aZdYNLtRM4JaYUTmEb0vWjwMqHrG58wcRKvHiu7irTd9qX2Bswo/o9Uhj7/oxRI60V+Yq+98jtMeAiyXOhjlLTCc4498mHb98XhjOSUHN3mypOupOq53w4DKsWoT+e7vS2qu3VwGDFzoi8wuqkvo55VNvroYLetYBfxd2p833R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718216561; c=relaxed/simple; bh=Sjnob0FuNgvdYrR12NY55cRxsHqSX6CzJ6C6bhV6cqw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZXvhTmge2CIreGlQaplLrdLpDLiUwskWcqv5SmwXSiiZ/bSNI/XAuo6wybC3Dv4hjQHmpy4bK2hPU9nI9lrFinYmY1Xmk35R3SlMJTF3WdGaEriaUMRwDd+yYU8xlnaVxqu+BJNw0WhLpjLJYlgq5gmQ2CeFY2cjhi0KtR7Kom8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718216558; h=from:from: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=olnAboc21BG3OoIDyOCCm8PsCd++0fbtlY8vvnIft0A=; b=dDJD1lCcR3M+zQ+09iE8+tKxEii7gaHPmcgjsldBx88L0P5tVWPiMzUfRGSufKgaG4LZsA UtKdV6K04G4ITSgQDKywRQ3gj7jcY4Ln9/ULNKSWEDbAseduoILP92tbo78X3+x8OSfGsj WYbSJehYmlgcUbtjZ6HLE6+1bai6LLM= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-376-gFHz-nAQPlWRlGv0PP3Stw-1; Wed, 12 Jun 2024 14:22:37 -0400 X-MC-Unique: gFHz-nAQPlWRlGv0PP3Stw-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-627dd6a56caso2544157b3.3 for ; Wed, 12 Jun 2024 11:22:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718216556; x=1718821356; 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=olnAboc21BG3OoIDyOCCm8PsCd++0fbtlY8vvnIft0A=; b=qMV/3SwOLuZGTTAUbSkIkUroDxhJs1Kdn9/kq8S4cTGJy2ANVHnzKBNcpEvGwj7NIk llIR6Y8zIAQ0WdTkTSe4HGXmp2Hx/PP1XGDK1gHVKo+RsVo/UIB+ToiXahA5MO263TtM K3Z2Yi+YDp/MYjnRu7jXJUd8g5gGAoSbqqgCBO0+vNj2zmqIgtoM4xoqTd90YUHnfYdx h74gqWq1yc3RAvJc28t8upvGMdDC8TTDoQ9i3ZiGiCROE/1I/0TnO8tMdwLkhNakHSst t2m7TB5yPXIglaEuIH/cmFgi9J37nT53/MDzD3t83TV4wzPwYy1MCDqukAM8wu3nRYv1 UbPw== X-Gm-Message-State: AOJu0YzHT1l4aPFef6di68HzgSNvrdloVN1UtedCITwKs1H7CCnJNCFH e2nskehy/tQMFCoI8qkFlKCViTQJafmt7PKVNRtIJ28wumyfp8feJrssrJ9aNXkVI4pOVUWzPg5 91dfUUfX9lLDSLqM5fWG/2uE93Bdk18nTOxpNcejMab/alzsRLOvXyKIgQA4m/1eOIipGwvoQTX /fNemthD52GShGZuy185AyO8Qs4RW2iFl6eVmm X-Received: by 2002:a0d:eb4d:0:b0:62f:7545:3eae with SMTP id 00721157ae682-62fb53e17dbmr28265457b3.0.1718216555933; Wed, 12 Jun 2024 11:22:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIpDls0R9BpRRIDVPitmKlEU0sS1q5NNtC6n3LQKRgLCgen23qxWzqKLq+mZTXQQlJN/6K1Q== X-Received: by 2002:a0d:eb4d:0:b0:62f:7545:3eae with SMTP id 00721157ae682-62fb53e17dbmr28265267b3.0.1718216555614; Wed, 12 Jun 2024 11:22:35 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4409fafb1cesm31626251cf.2.2024.06.12.11.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 11:22:35 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: undeclared identifier in requires-clause [PR99678] Date: Wed, 12 Jun 2024 14:22:33 -0400 Message-ID: <20240612182233.2716062-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.2.457.g8d94cfb545 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/14? -- >8 -- Since the terms of a requires-clause are grammatically primary-expressions rather than e.g. postfix-expressions, it seems we need to explicitly handle and diagnose the case where a term parses to bare unresolved unqualified-id, like cp_parser_postfix_expression does, since cp_parser_primary_expression doesn't do so itself. Otherwise we fail to reject the first three requires-clauses those below. Note that the only users of primary-expression in the C++ grammar are indeed postfix-expression and constraint-logical-and-expression, so it seems not so surprising that we need this special handling here. PR c++/99678 gcc/cp/ChangeLog: * parser.cc (cp_parser_constraint_primary_expression): Reject a bare unresolved unqualified-id. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires38.C: New test. --- gcc/cp/parser.cc | 2 ++ gcc/testsuite/g++.dg/cpp2a/concepts-requires38.C | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires38.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index bc4a2359153..0d59f7d2690 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -31496,6 +31496,8 @@ cp_parser_constraint_primary_expression (cp_parser *parser, bool lambda_p) } if (pce == pce_ok) { + if (idk == CP_ID_KIND_UNQUALIFIED && identifier_p (expr)) + expr = unqualified_name_lookup_error (expr); cp_lexer_commit_tokens (parser->lexer); return finish_constraint_primary_expr (expr); } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires38.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires38.C new file mode 100644 index 00000000000..663195b79cc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires38.C @@ -0,0 +1,14 @@ +// PR c++/99678 +// { dg-do compile { target c++20 } } + +template +void f1() requires undeclared_identifier; // { dg-error "not declared" } + +template +void f2() requires true && undeclared_identifier; // { dg-error "not declared" } + +template +void f3() requires false || undeclared_identifier; // { dg-error "not declared" } + +template +void f4() requires undeclared_identifier(T{}); // { dg-error "must be enclosed in parentheses" }