public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9828] c++: elaborated-type-spec in requires-expr [PR101677]
@ 2022-04-12 20:14 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-12 20:14 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:556d061e62ea863c7f99129219ca69bf0792c7f1

commit r11-9828-g556d061e62ea863c7f99129219ca69bf0792c7f1
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Mar 27 22:31:51 2022 -0400

    c++: elaborated-type-spec in requires-expr [PR101677]
    
    We were failing to declare class S in the global namespace because we were
    treating the requires-expression parameter scope as a normal block scope, so
    the implicit declaration went there.
    
    It seems to me that the requires parameter scope is more like a function
    parameter scope (not least in the use of the word "parameter"), so let's
    change the scope kind.  But then we need to adjust the prohibition on
    placeholders declaring implicit template parameters.
    
            PR c++/101677
    
    gcc/cp/ChangeLog:
    
            * name-lookup.h (struct cp_binding_level): Add requires_expression
            bit-field.
            * parser.c (cp_parser_requires_expression): Set it.
            (synthesize_implicit_template_parm): Check it.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts-pr67178.C: Adjust error.
            * g++.dg/cpp2a/concepts-requires28.C: New test.

Diff:
---
 gcc/cp/name-lookup.h                             |  5 ++++-
 gcc/cp/parser.c                                  |  5 +++--
 gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C    |  2 +-
 gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C | 13 +++++++++++++
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index f63c4f5b8bb..c6d0aa96b55 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -309,7 +309,10 @@ struct GTY(()) cp_binding_level {
   /* true for SK_FUNCTION_PARMS of immediate functions.  */
   unsigned immediate_fn_ctx_p : 1;
 
-  /* 22 bits left to fill a 32-bit word.  */
+  /* True for SK_FUNCTION_PARMS of a requires-expression.  */
+  unsigned requires_expression: 1;
+
+  /* 21 bits left to fill a 32-bit word.  */
 };
 
 /* The binding level currently in effect.  */
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f41b61c26df..90d119eaa28 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -28849,7 +28849,8 @@ cp_parser_requires_expression (cp_parser *parser)
       scope_sentinel ()
       {
 	++cp_unevaluated_operand;
-	begin_scope (sk_block, NULL_TREE);
+	begin_scope (sk_function_parms, NULL_TREE);
+	current_binding_level->requires_expression = true;
       }
 
       ~scope_sentinel ()
@@ -45383,7 +45384,7 @@ static tree
 synthesize_implicit_template_parm  (cp_parser *parser, tree constr)
 {
   /* A requires-clause is not a function and cannot have placeholders.  */
-  if (current_binding_level->kind == sk_block)
+  if (current_binding_level->requires_expression)
     {
       error ("placeholder type not allowed in this context");
       return error_mark_node;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C
index c74f6f00a5c..bdd5f9699e0 100644
--- a/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr67178.C
@@ -12,7 +12,7 @@ concept C0 = requires (auto x) { // { dg-error "placeholder type" }
 template<typename T>
 concept C1 = requires (C1 auto x) { // { dg-error "not been declared|placeholder|two or more|in requirements" }
   x; // { dg-error "not declared" }
-  { x } -> c; // { dg-message "is invalid" }
+  { x } -> c; // { dg-message "is invalid|not declared" }
 };
 
 template<typename T>
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C
new file mode 100644
index 00000000000..e632f0167f4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires28.C
@@ -0,0 +1,13 @@
+// PR c++/101677
+// { dg-do compile { target c++20 } }
+
+template<class T>
+concept C_bug_with_forward_decl = requires(T& t){
+    t.template f<class S>();
+};
+
+struct good {
+    template<class T> void f() {}
+};
+
+static_assert(C_bug_with_forward_decl<good>);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-12 20:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 20:14 [gcc r11-9828] c++: elaborated-type-spec in requires-expr [PR101677] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).