From patchwork Fri Feb 16 09:21:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 202011 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp394058dyb; Fri, 16 Feb 2024 01:22:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUDLka+Y7HSSssqMwUnmyOSwVwmeYOdYSpu+Z92XtN9TG0ep8iLOdWPLYj9CkMyjide7mOIQAulyxeJc5cTZcLMwV4tvQ== X-Google-Smtp-Source: AGHT+IEue3fnfqMbKLNjEFqbkzaOnL5isRHr0pcPMVx1F+HX/4g/I6Rw5PNepg4XIoZYIh1pLzFg X-Received: by 2002:a0c:e089:0:b0:68f:2a2b:c6e5 with SMTP id l9-20020a0ce089000000b0068f2a2bc6e5mr4508908qvk.31.1708075364752; Fri, 16 Feb 2024 01:22:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708075364; cv=pass; d=google.com; s=arc-20160816; b=y9fJ8HT5YekZKMCnItWDfwuzWvlDsa2AEN2Zw1lJQeIRMeRAa8GrF3z76EOdUWbX53 vluYePThbWzP7yh+APxZu3b6a+Fb7oxQXniad50QfIEyK5OT3vpJqeuw3pdZpp3oymaN FScxrhReGnMelwLXvF+bK6576h+cp4b+D7ZQnYmUVpWHRahBvC9NwX1RsbNOHUFS+g70 kpZzGKIOaqvES+ePK1smo6viJvpwtpMDep40xmooYxbVoG9aaVPXPiqh2lI1CH1jVQHv xilmoz6JgJ+jMhIUnQcgDWnNPRjw6N8Hu+K2Uwf3QgYUrOTAQauwB1BkF1ahTW8bw6ru bSEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=CVx7VPX33NCS/a5NuAJ7KsZUGuaqfbnwznAItMw91yM=; fh=0xZT+NBKSeH8qOu04/61f1ZGePpF4jF/gxp331YE14k=; b=sY5gxXPmiPqOqRqGVSsdXaj9l12tPZr9VIChj5jpBAtexlps4yehU8Vo3OFrMhaAgB AiMZF37ZoCM/uQarfS73GRIeWjw4EWFU7XLV6/phENwQftvNDbUrt+b+RykBGUe7GjPL wSBpt7jHO/GC8AbZteQ+GqZKZLzW8DoN+dxBYF/I9IvcoyiL0lWJeRvb/QXAq9tAQhJM 2p+iiDirRxrJbvOWEVCgPk61alHIR8kKcPPMQoP/2wZCXLKL/trIJrpyNc4Vv3h5EOsm cLWsiHwJHI9TM6KizLNVfyQqCllSPsCjURn4FaTQuBZSGQV2uyG5/D7bjpj2k7W0fNfP RfwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fh3bttuh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r3-20020a056214212300b0068ce33a4d9asi3702032qvc.423.2024.02.16.01.22.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 01:22:44 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fh3bttuh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B680385841A for ; Fri, 16 Feb 2024 09:22:44 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 30E1D3858C54 for ; Fri, 16 Feb 2024 09:22:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30E1D3858C54 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 30E1D3858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708075322; cv=none; b=tOsjdsZlkx7GD/UmKOC1LvDlGff+xJS2GnohHkbVklc0ukXWaXEC/bqxlvpAdVRbuINS23rO/3W/qJF7hc+Fsn3MkfMUDPLCFeJOnC2m60W6P9RngKaMI8WwKZt3ywOwsho1dRlOffnLM11MpB/FOrkPjZDbNf76x14moN3WXfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708075322; c=relaxed/simple; bh=dPTwt9GeCd6WxTQB1suaoqfmaE/TKmXVixS9brQu6xM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=FH3HhhunjEO4xI+NRXsbB9w/UyAvBZVLvUs75Z3kGl8A5J4KbHBdPYLJItKCZnQ7xG93bnT9h6Py//KjuYVwuzHpzan2EPBZ2APL3aKIHRRSkYXaICzq8X2QIF7jTgE2taYelkZvbjkf/HEgcnBg9ZB1is2YDVnp0clqlZRbut0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708075319; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=CVx7VPX33NCS/a5NuAJ7KsZUGuaqfbnwznAItMw91yM=; b=fh3bttuhMZQKZnPW93ioMYRZV0tAdqNq5nk9jN3ijBZ45Rv3atPO/NPdH86+JfLPgAxuOk IbJbLdk3Z3FSY12ANhoZ7idzwj6g7sGabn5pgAUwF262z7b3KX6SkJTOPNsLYgkRaNnH8J 73XSFKIA9JNyXcX1JCHqA0zp3Nu20To= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-Z6TBEjYoPuGWP22jbXPNkw-1; Fri, 16 Feb 2024 04:21:58 -0500 X-MC-Unique: Z6TBEjYoPuGWP22jbXPNkw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00E573813F32 for ; Fri, 16 Feb 2024 09:21:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AC478CED; Fri, 16 Feb 2024 09:21:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41G9Ltik4070413 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Feb 2024 10:21:55 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41G9LsDx4070412; Fri, 16 Feb 2024 10:21:54 +0100 Date: Fri, 16 Feb 2024 10:21:54 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Diagnose this specifier on template parameters [PR113929] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791046833324661180 X-GMAIL-MSGID: 1791046833324661180 Hi! For template parameters, the optional this specifier is in the grammar template-parameter-list -> template-parameter -> parameter-declaration, just [dcl.fct/6] says that it is only valid in parameter-list of certain functions. So, unlike the case of decl-specifier-seq used in non-terminals other than parameter-declaration, I think it is better not to fix this by cp_parser_decl_specifier_seq (parser, - flags | CP_PARSER_FLAGS_PARAMETER, + flags | (template_parameter_p ? 0 + : CP_PARSER_FLAGS_PARAMETER), &decl_specifiers, &declares_class_or_enum); which would be pretending it isn't in the grammar, but by diagnosing it separately, which is what the following patch does. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-16 Jakub Jelinek PR c++/113929 * parser.cc (cp_parser_parameter_declaration): Diagnose this specifier on template parameter declaration. * g++.dg/parse/pr113929.C: New test. Jakub --- gcc/cp/parser.cc.jj 2024-02-15 17:33:11.641453437 +0100 +++ gcc/cp/parser.cc 2024-02-15 17:40:29.592447265 +0100 @@ -25724,8 +25724,15 @@ cp_parser_parameter_declaration (cp_pars for a C-style variadic function. */ token = cp_lexer_peek_token (parser->lexer); - bool const xobj_param_p + bool xobj_param_p = decl_spec_seq_has_spec_p (&decl_specifiers, ds_this); + if (xobj_param_p && template_parm_p) + { + error_at (decl_specifiers.locations[ds_this], + "% specifier in template parameter declaration"); + xobj_param_p = false; + decl_specifiers.locations[ds_this] = 0; + } bool diag_xobj_parameter_pack = false; if (xobj_param_p && (declarator && declarator->parameter_pack_p)) --- gcc/testsuite/g++.dg/parse/pr113929.C.jj 2024-02-15 17:43:18.500129688 +0100 +++ gcc/testsuite/g++.dg/parse/pr113929.C 2024-02-15 17:42:54.564458109 +0100 @@ -0,0 +1,7 @@ +// PR c++/113929 +// { dg-do compile } + +template // { dg-error "'this' specifier in template parameter declaration" } +struct S {}; +template // { dg-error "'this' specifier in template parameter declaration" } +struct T {};