aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/lambda.c
diff options
context:
space:
mode:
authorJeff Chapman II <jchapman@lock3software.com>2019-10-30 22:31:48 -0400
committerJason Merrill <jason@gcc.gnu.org>2019-10-30 22:31:48 -0400
commite4c431266f9aaf604edfca68e852ae8efe966e8e (patch)
tree7f8442e216b2d8722a38b040707deedc3c3da7cd /gcc/cp/lambda.c
parent56e0346dcb882b07199b8b19616b52f9667e356f (diff)
downloadgcc-e4c431266f9aaf604edfca68e852ae8efe966e8e.zip
gcc-e4c431266f9aaf604edfca68e852ae8efe966e8e.tar.gz
gcc-e4c431266f9aaf604edfca68e852ae8efe966e8e.tar.bz2
PR c++/84810 - constraints on lambdas
Attached is a patch that adds parsing of the optional requires-clause in a lambda-expression and lambda-declarator. Additionally, shorthand constraints from the template-parameter-list are now actually applied and constrain the synthesized operator(). Previously we were not parsing the requires clauses at all and not saving the shorthand constraints in the place expected by grokfndecl. The trailing requires-clause is now also used to suppress synthesis of the conversion to function pointer for non-capturing non-generic lambdas as per expr.prim.lambda.closure/7. This includes a fix to template_class_depth. Previously it was computing the wrong depth for lambdas in the initializer of a static member of a class template, exhibited by the concepts-lambda4 test which currently fails on trunk. The bug was causing grokfndecl to use the constraints from the template class for the lambda. gcc/cp/ 2019-10-30 Jeff Chapman II <jchapman@lock3software.com> PR c++/84810 - constraints on lambdas * lambda.c (maybe_add_lambda_conv_op): Do not synthesize conversion if the call operator does not satisfy its constraints. * parser.c (cp_parser_lambda_declarator_opt): Parse requires-clause on generic lambdas; combine with shorthand constraints. Parse trailing requires-clause and attach to the synthesized call operator. * pt.c (template_class_depth): Only inspect LAMBDA_TYPE_EXTRA_SCOPE if it is present. This fixes an incorrect depth calculation for lambdas inside the initializer of a static data member of a template class. gcc/testsuite/ 2019-10-30 Jeff Chapman II <jchapman@lock3software.com> PR c++/84810 - constraints on lambdas * g++.dg/cpp2a/concepts-lambda2.C: New test. * g++.dg/cpp2a/concepts-lambda3.C: Ditto. * g++.dg/cpp2a/concepts-lambda4.C: Ditto. * g++.dg/cpp2a/concepts-pr84810.C: Ditto. From-SVN: r277655
Diffstat (limited to 'gcc/cp/lambda.c')
-rw-r--r--gcc/cp/lambda.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index f128ed8..d621bec 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -1046,6 +1046,12 @@ maybe_add_lambda_conv_op (tree type)
return;
}
+ /* Non-generic non-capturing lambdas only have a conversion function to
+ pointer to function when the trailing requires-clause's constraints are
+ satisfied. */
+ if (!generic_lambda_p && !constraints_satisfied_p (callop))
+ return;
+
/* Non-template conversion operators are defined directly with build_call_a
and using DIRECT_ARGVEC for arguments (including 'this'). Templates are
deferred and the CALL is built in-place. In the case of a deduced return