c++: diagnose this specifier in requires expr [PR116798]
We don't detect an explicit object parameter in a requires expression. We can get there by way of requires-expression -> requirement-parameter-list -> parameter-declaration-clause -> ... -> parameter-declaration with this[opt]. But [dcl.fct]/5 doesn't allow an explicit object parameter in this context. So let's fix it like r14-9033 and not like r14-8832. PR c++/116798 gcc/cp/ChangeLog: * parser.cc (cp_parser_parameter_declaration): Detect an explicit object parameter in a requires expression. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-diagnostics12.C: New test. Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
parent
c1fb78fb03
commit
4700ad1c78
2 changed files with 18 additions and 3 deletions
|
@ -25982,10 +25982,15 @@ cp_parser_parameter_declaration (cp_parser *parser,
|
|||
|
||||
bool xobj_param_p
|
||||
= decl_spec_seq_has_spec_p (&decl_specifiers, ds_this);
|
||||
if (xobj_param_p && template_parm_p)
|
||||
if (xobj_param_p
|
||||
&& (template_parm_p || current_binding_level->requires_expression))
|
||||
{
|
||||
error_at (decl_specifiers.locations[ds_this],
|
||||
"%<this%> specifier in template parameter declaration");
|
||||
if (template_parm_p)
|
||||
error_at (decl_specifiers.locations[ds_this],
|
||||
"%<this%> specifier in template parameter declaration");
|
||||
else
|
||||
error_at (decl_specifiers.locations[ds_this],
|
||||
"%<this%> specifier in a requires-expression parameter");
|
||||
xobj_param_p = false;
|
||||
decl_specifiers.locations[ds_this] = 0;
|
||||
}
|
||||
|
|
10
gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics12.C
Normal file
10
gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics12.C
Normal file
|
@ -0,0 +1,10 @@
|
|||
// PR c++/116798
|
||||
// { dg-do compile { target c++23 } }
|
||||
|
||||
template<typename T>
|
||||
concept C = requires(this T u, // { dg-error "'this' specifier in a requires-expression parameter" }
|
||||
this T v) { // { dg-error "'this' specifier in a requires-expression parameter" }
|
||||
u + v;
|
||||
};
|
||||
|
||||
static_assert(C<int>);
|
Loading…
Add table
Reference in a new issue