diff mbox series

c++: reject packs on xobj params. [PR113307]

Message ID URy3NE96yeGE31Mp0tUrFWcaWV3n9RgmY1oyBc9e-biCFWAEVhGKxMuKRZF3YOwmaCv3sFX3X9jJUhOjFV2wikLGeKIJVsHAfTcsdUR43ss=@protonmail.com
State New
Headers show
Series c++: reject packs on xobj params. [PR113307] | expand

Commit Message

waffl3x Jan. 12, 2024, 7:40 a.m. UTC
Bootstrapped and tested on x86_64-linux with no regressions.

I'm still getting used to things so let me know if the change log
entries are excessive, thanks.

Comments

Jakub Jelinek Jan. 12, 2024, 8:48 a.m. UTC | #1
On Fri, Jan 12, 2024 at 07:40:19AM +0000, waffl3x wrote:
> Bootstrapped and tested on x86_64-linux with no regressions.
> 
> I'm still getting used to things so let me know if the change log
> entries are excessive, thanks.

> From 9dc168e7bcbbd7d515fa28cb9cae28ec113fae0f Mon Sep 17 00:00:00 2001
> From: Waffl3x <waffl3x@protonmail.com>
> Date: Thu, 11 Jan 2024 14:32:46 -0700
> Subject: [PATCH] c++: reject packs on xobj params. [PR113307]
> 
> Reject and diagnose xobj parameters declared as parameter packs.
> 
> 	PR c++/113307
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_parameter_declaration): Reject packs
> 	on xobj params.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp23/explicit-obj-diagnostics3.C: Add test for
> 	rejection of packs.
> 
> Signed-off-by: Waffl3x <waffl3x@protonmail.com>
> ---
>  gcc/cp/parser.cc                              |  21 +++-
>  .../g++.dg/cpp23/explicit-obj-diagnostics3.C  | 106 +++++++++++++++++-
>  2 files changed, 125 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 8ab98cc0c23..70fbba09bf8 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -25706,6 +25706,25 @@ cp_parser_parameter_declaration (cp_parser *parser,
>       for a C-style variadic function. */
>    token = cp_lexer_peek_token (parser->lexer);
>  
> +  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)))
> +    {
> +      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");

Formatting - there should be space before ( and the following 2 lines
should be indented accordingly.

Will defer to Jason for the rest.

	Jakub
Jason Merrill Jan. 16, 2024, 9:11 p.m. UTC | #2
On 1/12/24 03:48, Jakub Jelinek wrote:
> On Fri, Jan 12, 2024 at 07:40:19AM +0000, waffl3x wrote:
>> Bootstrapped and tested on x86_64-linux with no regressions.
>>
>> I'm still getting used to things so let me know if the change log
>> entries are excessive, thanks.
> 
>>  From 9dc168e7bcbbd7d515fa28cb9cae28ec113fae0f Mon Sep 17 00:00:00 2001
>> From: Waffl3x <waffl3x@protonmail.com>
>> Date: Thu, 11 Jan 2024 14:32:46 -0700
>> Subject: [PATCH] c++: reject packs on xobj params. [PR113307]
>>
>> Reject and diagnose xobj parameters declared as parameter packs.
>>
>> 	PR c++/113307
>>
>> gcc/cp/ChangeLog:
>>
>> 	* parser.cc (cp_parser_parameter_declaration): Reject packs
>> 	on xobj params.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 	* g++.dg/cpp23/explicit-obj-diagnostics3.C: Add test for
>> 	rejection of packs.
>>
>> Signed-off-by: Waffl3x <waffl3x@protonmail.com>
>> ---
>>   gcc/cp/parser.cc                              |  21 +++-
>>   .../g++.dg/cpp23/explicit-obj-diagnostics3.C  | 106 +++++++++++++++++-
>>   2 files changed, 125 insertions(+), 2 deletions(-)
>>
>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
>> index 8ab98cc0c23..70fbba09bf8 100644
>> --- a/gcc/cp/parser.cc
>> +++ b/gcc/cp/parser.cc
>> @@ -25706,6 +25706,25 @@ cp_parser_parameter_declaration (cp_parser *parser,
>>        for a C-style variadic function. */
>>     token = cp_lexer_peek_token (parser->lexer);
>>   
>> +  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)))
>> +    {
>> +      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");
> 
> Formatting - there should be space before ( and the following 2 lines
> should be indented accordingly.
> 
> Will defer to Jason for the rest.

Pushed with that fixed, thanks.

Jason
diff mbox series

Patch

From 9dc168e7bcbbd7d515fa28cb9cae28ec113fae0f Mon Sep 17 00:00:00 2001
From: Waffl3x <waffl3x@protonmail.com>
Date: Thu, 11 Jan 2024 14:32:46 -0700
Subject: [PATCH] c++: reject packs on xobj params. [PR113307]

Reject and diagnose xobj parameters declared as parameter packs.

	PR c++/113307

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_parameter_declaration): Reject packs
	on xobj params.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp23/explicit-obj-diagnostics3.C: Add test for
	rejection of packs.

Signed-off-by: Waffl3x <waffl3x@protonmail.com>
---
 gcc/cp/parser.cc                              |  21 +++-
 .../g++.dg/cpp23/explicit-obj-diagnostics3.C  | 106 +++++++++++++++++-
 2 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 8ab98cc0c23..70fbba09bf8 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -25706,6 +25706,25 @@  cp_parser_parameter_declaration (cp_parser *parser,
      for a C-style variadic function. */
   token = cp_lexer_peek_token (parser->lexer);
 
+  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)))
+    {
+      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");
+      /* Suppress errors that occur down the line.  */
+      if (declarator)
+	declarator->parameter_pack_p = false;
+    }
+
   /* If a function parameter pack was specified and an implicit template
      parameter was introduced during cp_parser_parameter_declaration,
      change any implicit parameters introduced into packs.  */
@@ -25829,7 +25848,7 @@  cp_parser_parameter_declaration (cp_parser *parser,
   if (default_argument)
     STRIP_ANY_LOCATION_WRAPPER (default_argument);
 
-  if (decl_spec_seq_has_spec_p (&decl_specifiers, ds_this))
+  if (xobj_param_p)
     {
       if (default_argument)
 	{
diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics3.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics3.C
index ec091d6ca67..304cf029f8f 100644
--- a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics3.C
+++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics3.C
@@ -1,7 +1,9 @@ 
 // P0847R7
 // { dg-do compile { target c++23 } }
 
-// rejection and diagnosis of an xobj parameter declared with a default argument
+// rejection and diagnosis of an incorrectly declared xobj parameter
+
+// default argument
 
 struct S {
   void f0(this S = {}) {} // { dg-error "an explicit object parameter may not have a default argument" }
@@ -18,3 +20,105 @@  void S::f2(this S = {}) {} // { dg-error "an explicit object parameter may not h
 void S::f11(this S s) {}
 void S::f12(this S s = {}) {} // { dg-error "an explicit object parameter may not have a default argument" }
 
+// parameter pack
+
+struct S0 {
+  template<typename Selves>
+  void f(this Selves...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  void g(this Selves... selves) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  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<typename Selves>
+  void fd(this Selves...);  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  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" }
+};
+
+struct S1 {
+  template<typename Selves>
+  void f(this Selves&...) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  void g(this Selves&... selves) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  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<typename Selves>
+  void fd(this Selves&...);  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  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" }
+};
+
+struct S2 {
+  template<typename Selves>
+  void f(this Selves&&...) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  void g(this Selves&&... selves) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  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<typename Selves>
+  void fd(this Selves&&...);  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  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" }
+};
+
+struct S3 {
+  template<typename Selves>
+  void f(this Selves const&...) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  void g(this Selves const&... selves) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  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<typename Selves>
+  void fd(this Selves const&...);  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  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" }
+};
+
+struct S4 {
+  template<typename Selves>
+  void f(this Selves const&&...) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  void g(this Selves const&&... selves) {}  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  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<typename Selves>
+  void fd(this Selves const&&...);  // { dg-error "an explicit object parameter cannot be a function parameter pack" }
+
+  template<typename Selves>
+  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" }
+};
+
-- 
2.43.0