[gcc r15-3812] c++: diagnose this specifier in requires expr [PR116798]
Marek Polacek
mpolacek@gcc.gnu.org
Mon Sep 23 19:33:20 GMT 2024
https://gcc.gnu.org/g:4700ad1c78ccd7767f846802fca148b2ea9a1852
commit r15-3812-g4700ad1c78ccd7767f846802fca148b2ea9a1852
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Sep 23 12:19:40 2024 -0400
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>
Diff:
---
gcc/cp/parser.cc | 11 ++++++++---
gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics12.C | 10 ++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 4dd9474cf609..dbc607027dfb 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;
}
diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics12.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics12.C
new file mode 100644
index 000000000000..ec0aced0fd9c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics12.C
@@ -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>);
More information about the Gcc-cvs
mailing list