From: waffl3x Date: Fri, 12 Jan 2024 07:40:19 +0000 (+0000) Subject: c++: reject packs on xobj params [PR113307] X-Git-Tag: basepoints/gcc-15~1976 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6aae831a3fe6619794afa79410e6fc1b4817f0b1;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index c7ad3ecd3edf..3748ccd49ff3 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -25714,6 +25714,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. */ @@ -25837,7 +25856,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 ec091d6ca674..304cf029f8f0 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 + void f(this Selves...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + template + 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 + void fd(this Selves...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + 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" } +}; + +struct S1 { + template + void f(this Selves&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + template + 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 + void fd(this Selves&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + 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" } +}; + +struct S2 { + template + void f(this Selves&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + template + 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 + void fd(this Selves&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + 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" } +}; + +struct S3 { + template + void f(this Selves const&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + template + 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 + void fd(this Selves const&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + 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" } +}; + +struct S4 { + template + void f(this Selves const&&...) {} // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + template + 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 + void fd(this Selves const&&...); // { dg-error "an explicit object parameter cannot be a function parameter pack" } + + 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" } +}; +