Implement P0315R4, Lambdas in unevaluated contexts.
authorJason Merrill <jason@redhat.com>
Tue, 13 Nov 2018 04:49:09 +0000 (23:49 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 13 Nov 2018 04:49:09 +0000 (23:49 -0500)
commit0c1e0d63fe0ceabbd04384070f3b59f8bf50de09
treeccbb8ff54004ee0dd964a8e4e5621030bf011aa9
parent7d119905abdf28f56486be0ca01a42f8efcea1a2
Implement P0315R4, Lambdas in unevaluated contexts.

When lambdas were added in C++11 they were banned from unevaluated contexts
as a way to avoid needing to deal with them in mangling or SFINAE.  This
proposal avoids that with a more narrow proposal: lambdas never compare as
equivalent (so we don't need to mangle them), and substitution failures
within a lambda are hard errors.  Lambdas appearing in places that types
couldn't previously have been declared introduces various complications; in
particular, it seems likely to mean types with no linkage being used more
broadly, risking ODR violations.  I want to follow up this patch with some
related diagnostics.

* decl2.c (min_vis_expr_r): Handle LAMBDA_EXPR.
* mangle.c (write_expression): Handle LAMBDA_EXPR.
* parser.c (cp_parser_lambda_expression): Allow lambdas in
unevaluated context.  Start the tentative firewall sooner.
(cp_parser_lambda_body): Use cp_evaluated.
* pt.c (iterative_hash_template_arg): Handle LAMBDA_EXPR.
(tsubst_function_decl): Substitute a lambda even if it isn't
dependent.
(tsubst_lambda_expr): Use cp_evaluated.  Always complain.
(tsubst_copy_and_build) [LAMBDA_EXPR]: Do nothing if tf_partial.
* semantics.c (begin_class_definition): Allow in template parm list.
* tree.c (strip_typedefs_expr): Pass through LAMBDA_EXPR.
(cp_tree_equal): Handle LAMBDA_EXPR.

From-SVN: r266056
22 files changed:
gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/mangle.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/cp/tree.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice6.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-sfinae1.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-uneval2.C
gcc/testsuite/g++.dg/cpp2a/lambda-uneval1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval9.cc [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-uneval9.h [new file with mode: 0644]