From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 C38C23857B8B for ; Fri, 16 Feb 2024 20:47:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C38C23857B8B 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 C38C23857B8B 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=1708116469; cv=none; b=XT0GlOX41RqWpjrhRiFZ5dTbLcJlW+0FSqShbYjiF5bTc5JhzDUD2APM8RBk5Nhg/a1FIUGbTq0LuGUtDfUsTKBOSpyS8BJUi/NBbHRXrGl7YFqIJT5hwbkTJ73Bh/QrkIVH+Sk8S42W6rLI/fBRecm9Ef8MOX06pl8KDj0fHaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708116469; c=relaxed/simple; bh=rEBI1qs0WhgC1nbk6MY46U8y1a/HQCF/gC9Qsi3CJjI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=C0Cy1IlqIhtzipI3LrxBD43X5gdBSWuoNIB8ngd89VlcZoesS/VSDyB84zugg+eW+vGY7d3klkK2Z7UP3a8SXqsNveAoVAZ/E4RvOFh+jNoZrbhSa5mea/2bV3Z4jQZ40ZB+RDfqlfy/xDm9Hfl1AaalHbT/dlvL1yJ93REcKr8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708116466; 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: in-reply-to:in-reply-to:references:references; bh=vUdRJLqEeccwJrcykJfGzC0Zov9ivAETIWMkQcjCy+I=; b=KptI5MuZJMxtHjNDR7miMgRipvgULGrEN38xzk7JN+6bcwIxRdN0y3xrdI7Ojjum2y3yxs 94m+80AUPGA35zchQYjs3rKb+yZiqCSJuD4I9CATxoNBuTOUqGuaOGYziFhENSJmuAqX2H 05vQCZz9f1ciKQzVuxrpsUdfUP+eLbk= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-8wGE-m-LNzeShNrSg3hoCQ-1; Fri, 16 Feb 2024 15:47:44 -0500 X-MC-Unique: 8wGE-m-LNzeShNrSg3hoCQ-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-60761bdbd4cso43390427b3.3 for ; Fri, 16 Feb 2024 12:47:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708116464; x=1708721264; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vUdRJLqEeccwJrcykJfGzC0Zov9ivAETIWMkQcjCy+I=; b=ORp4Mja/RXJhTzG+n7N+hgVsl8Gt2/I8TOMSTKenDu1qv3mZu7limZWRDac6E5M6qY o4vvjLTKFKRDwF1M+/4nFYkpktjuSvOkKFLIoGOlm75GfLCZiwNfb1U3B9pIZzggdguz s4QOq9d4bbSiiWAkd1LufjBBP8ZypJxP/jdGOmrHsm80Q9enoUVUd858DXj74QvE595g sDjG2EwCpdW3tGBSyhZTCUCuYiJIb0iFLGoJDIewbUfACewnZp9Tf7OzffE10maRkBeN qMvL7hLWQbOj1rW1ByRMvtxVHOFtydSwy5KLdLOY+gqa0rJyHMeRcNF5Ft9AgsR/IVxY sV1g== X-Gm-Message-State: AOJu0YzY4Fs8BgvIihKPLRkjp3VCxzVGz7Qf0vCi1LT70ioDCV9WClUw eb6FmDJkKzd6ffb05l2aGE84ZdcMD2dCZtTgglOFuKhJwjo4n/d0Nc33zwH7sQY6Pp8+cw94QIn ykD27FzeICCPjsZHD7Sa/0imxkyrypl64h3pIkNe0oh41FthzBzarMLGVz6Ntat4= X-Received: by 2002:a0d:eb12:0:b0:604:c8e7:9dcf with SMTP id u18-20020a0deb12000000b00604c8e79dcfmr6754717ywe.35.1708116463869; Fri, 16 Feb 2024 12:47:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjWQcHS+h1SSz9FS3ucUM1YsOZwVJZBZtsSHmd1cj3jqwYCzMX5o1mvVazIjDnEDJpgyYlFQ== X-Received: by 2002:a0d:eb12:0:b0:604:c8e7:9dcf with SMTP id u18-20020a0deb12000000b00604c8e79dcfmr6754699ywe.35.1708116463416; Fri, 16 Feb 2024 12:47:43 -0800 (PST) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id o19-20020ac87c53000000b0042c723627a4sm259519qtv.24.2024.02.16.12.47.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 12:47:42 -0800 (PST) Message-ID: <76a12c05-670d-4c56-8d5a-60cdbba32f84@redhat.com> Date: Fri, 16 Feb 2024 15:47:41 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: Fix up parameter pack diagnostics on xobj vs. varargs functions [PR113802] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 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_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 List-Id: On 2/16/24 04:03, Jakub Jelinek wrote: > Hi! > > The simple presence of ellipsis as next token after the parameter > declaration doesn't imply it is a parameter pack, it sometimes is, e.g. > if its type is a pack, but sometimes is not and in that case it acts > the same as if the next tokens were , ... instead of just ... > The xobj param cannot be a function parameter pack though treats both > the declarator->parameter_pack_p and token->type == CPP_ELLIPSIS as > sufficient conditions for the error. The conditions for CPP_ELLIPSIS > are done a little bit later in the same function and complex enough that > IMHO shouldn't be repeated, on the other side for the > declarator->parameter_pack_p case we clear that flag for xobj params > for error recovery reasons. > In order to avoid diagnosing this in two spots, one at the current spot > for declarator->parameter_pack_p and one for the ellipsis case after > we decide if it is parameter pack or varargs, the following patch instead > just sets a boolean flag whether we should emit this diagnostics, does it > early for declarator->parameter_pack_p case and clears the parameter_pack_p > flag in that case like the older patch did, and for the ellipsis case > sets the flag later, then emits the diagnostics. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2024-02-16 Jakub Jelinek > > PR c++/113802 > * parser.cc (cp_parser_parameter_declaration): Don't emit > PR113307 diagnostics too early, instead for the > declarator->parameter_pack_p case just set a flag it should be emitted > later. Set that flag also when consuming following ellipsis as part > of a parameter pack and diagnose either afterwards. Formatting fix. > > * g++.dg/cpp23/explicit-obj-diagnostics3.C (S0, S1, S2, S3, S4): Don't > expect any diagnostics on f and fd member function templates, add > similar templates with ...Selves instead of Selves as k and kd and > expect diagnostics for those. > > --- gcc/cp/parser.cc.jj 2024-02-14 14:26:19.000000000 +0100 > +++ gcc/cp/parser.cc 2024-02-15 11:58:27.033618967 +0100 > @@ -25727,17 +25727,10 @@ cp_parser_parameter_declaration (cp_pars > bool const xobj_param_p > = decl_spec_seq_has_spec_p (&decl_specifiers, ds_this); > > - if (xobj_param_p > - && ((declarator && declarator->parameter_pack_p) > - || cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))) > + bool diag_xobj_parameter_pack = false; > + if (xobj_param_p && (declarator && declarator->parameter_pack_p)) > { > - location_t xobj_param > - = make_location (decl_specifiers.locations[ds_this], > - decl_spec_token_start->location, > - input_location); > - error_at (xobj_param, > - "an explicit object parameter cannot " > - "be a function parameter pack"); > + diag_xobj_parameter_pack = true; > /* Suppress errors that occur down the line. */ > if (declarator) > declarator->parameter_pack_p = false; > @@ -25755,9 +25748,10 @@ cp_parser_parameter_declaration (cp_pars > (INNERMOST_TEMPLATE_PARMS (current_template_parms)); > > if (latest_template_parm_idx != template_parm_idx) > - decl_specifiers.type = convert_generic_types_to_packs > - (decl_specifiers.type, > - template_parm_idx, latest_template_parm_idx); > + decl_specifiers.type > + = convert_generic_types_to_packs (decl_specifiers.type, > + template_parm_idx, > + latest_template_parm_idx); > } > > if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS)) > @@ -25773,6 +25767,8 @@ cp_parser_parameter_declaration (cp_pars > || (!type && template_parm_p)) > && declarator_can_be_parameter_pack (declarator)) > { > + if (xobj_param_p) > + diag_xobj_parameter_pack = true; > /* Consume the `...'. */ > cp_lexer_consume_token (parser->lexer); > maybe_warn_variadic_templates (); > @@ -25787,6 +25783,17 @@ cp_parser_parameter_declaration (cp_pars > } > } > > + if (diag_xobj_parameter_pack) Can we move all the xobj handling down here (where we can trust declarator->parameter_pack_p) instead of adding a new variable? > + { > + location_t xobj_param > + = make_location (decl_specifiers.locations[ds_this], > + decl_spec_token_start->location, > + input_location); > + error_at (xobj_param, > + "an explicit object parameter cannot " > + "be a function parameter pack"); > + } > + > /* The restriction on defining new types applies only to the type > of the parameter, not to the default argument. */ > parser->type_definition_forbidden_message = saved_message; > --- gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics3.C.jj 2024-01-17 10:34:49.812597960 +0100 > +++ gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics3.C 2024-02-15 12:14:29.994356800 +0100 > @@ -24,7 +24,7 @@ void S::f12(this S s = {}) {} // { dg-er > > struct S0 { > template > - void f(this Selves...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void f(this Selves...) {} > > template > void g(this Selves... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > @@ -32,19 +32,25 @@ struct S0 { > void h(this auto...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void j(this auto... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > + template > + void k(this Selves...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > template > - void fd(this Selves...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void fd(this Selves...); > > template > void gd(this Selves... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > void hd(this auto...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void jd(this auto... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > + template > + void kd(this Selves...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > }; > > struct S1 { > template > - void f(this Selves&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void f(this Selves&...) {} > > template > void g(this Selves&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > @@ -52,19 +58,25 @@ struct S1 { > void h(this auto&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void j(this auto&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > + template > + void k(this Selves&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > template > - void fd(this Selves&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void fd(this Selves&...); > > template > void gd(this Selves&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > void hd(this auto&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void jd(this auto&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > + template > + void kd(this Selves&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > }; > > struct S2 { > template > - void f(this Selves&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void f(this Selves&&...) {} > > template > void g(this Selves&&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > @@ -72,19 +84,25 @@ struct S2 { > void h(this auto&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void j(this auto&&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > + template > + void k(this Selves&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > template > - void fd(this Selves&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void fd(this Selves&&...); > > template > void gd(this Selves&&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > void hd(this auto&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void jd(this auto&&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > + template > + void kd(this Selves&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > }; > > struct S3 { > template > - void f(this Selves const&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void f(this Selves const&...) {} > > template > void g(this Selves const&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > @@ -92,19 +110,25 @@ struct S3 { > void h(this auto const&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void j(this auto const&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > + template > + void k(this Selves const&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > template > - void fd(this Selves const&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void fd(this Selves const&...); > > template > void gd(this Selves const&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > void hd(this auto const&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void jd(this auto const&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > + template > + void kd(this Selves const&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > }; > > struct S4 { > template > - void f(this Selves const&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void f(this Selves const&&...) {} > > template > void g(this Selves const&&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > @@ -112,13 +136,18 @@ struct S4 { > void h(this auto const&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void j(this auto const&&... selves) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > + template > + void k(this Selves const&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + > template > - void fd(this Selves const&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > + void fd(this Selves const&&...); > > template > void gd(this Selves const&&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > > void hd(this auto const&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > void jd(this auto const&&... selves); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > -}; > > + template > + void kd(this Selves const&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } > +}; > > Jakub >