aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/pt.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-05-26 22:43:05 -0400
committerJason Merrill <jason@redhat.com>2022-05-27 23:43:54 -0400
commit221acd67ca50f8f069037e034a3250f13d75a9f5 (patch)
tree3ea19b804a58d1514f5dd303d2cb234fd750ec3a /gcc/cp/pt.cc
parentd9176e643f385c3ef3b8c28cbc0468776fd8a14f (diff)
downloadgcc-221acd67ca50f8f069037e034a3250f13d75a9f5.zip
gcc-221acd67ca50f8f069037e034a3250f13d75a9f5.tar.gz
gcc-221acd67ca50f8f069037e034a3250f13d75a9f5.tar.bz2
c++: lambda in concept [PR105652]
We currently check satisfaction in the context of the constrained declaration (which may be wrong, see PR104111). When checking C<int> for S<int>, we currently substitute into the lambda in the context of S<T> (rather than S<int>, which seems wrong if the above isn't wrong), so the new closure type thinks its context is S<T>, which confuses debug output. For the moment, let's work around all of this by overriding the context of the closure. PR c++/105652 gcc/cp/ChangeLog: * pt.cc (tsubst_lambda_expr): Don't let a namespace-scope lambda instantiate into a class-scope lambda. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda20.C: New test.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r--gcc/cp/pt.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 24bbe2f..f1f0805 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -19740,11 +19740,18 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
return error_mark_node;
if (LAMBDA_EXPR_EXTRA_SCOPE (t) == NULL_TREE)
- /* A lambda in a default argument outside a class gets no
- LAMBDA_EXPR_EXTRA_SCOPE, as specified by the ABI. But
- tsubst_default_argument calls start_lambda_scope, so we need to
- specifically ignore it here, and use the global scope. */
- record_null_lambda_scope (r);
+ {
+ /* A lambda in a default argument outside a class gets no
+ LAMBDA_EXPR_EXTRA_SCOPE, as specified by the ABI. But
+ tsubst_default_argument calls start_lambda_scope, so we need to
+ specifically ignore it here, and use the global scope. */
+ record_null_lambda_scope (r);
+
+ /* If we're pushed into another scope (PR105652), fix it. */
+ if (TYPE_NAMESPACE_SCOPE_P (TREE_TYPE (t)))
+ TYPE_CONTEXT (type) = DECL_CONTEXT (TYPE_NAME (type))
+ = TYPE_CONTEXT (TREE_TYPE (t));
+ }
else
record_lambda_scope (r);