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: 85862 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 CED243858295 for ; Fri, 16 Feb 2024 09:22:29 +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+patchwork=sourceware.org@gcc.gnu.org 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 {};