aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-09-23 12:19:40 -0400
committerMarek Polacek <polacek@redhat.com>2024-09-23 15:24:07 -0400
commit4700ad1c78ccd7767f846802fca148b2ea9a1852 (patch)
treed1766e6f30630745d78b984d82746f1d16300ca5 /gcc/cp
parentc1fb78fb03caede01b02a1ebb3275ac98343d468 (diff)
downloadgcc-4700ad1c78ccd7767f846802fca148b2ea9a1852.zip
gcc-4700ad1c78ccd7767f846802fca148b2ea9a1852.tar.gz
gcc-4700ad1c78ccd7767f846802fca148b2ea9a1852.tar.bz2
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>
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/parser.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 4dd9474..dbc6070 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -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;
}