8sa1-gcc/gcc/cp
Patrick Palka 123b3e03c9 c++: Don't substitute into constraints on lambdas [PR99874]
We currently substitute through a lambda's constraints whenever we
regenerate it via tsubst_lambda_expr.  This is the wrong approach
because it can lead to hard errors due to constraints being evaluated
out of order (as in the testcase concepts-lambda17.C below), and because
it doesn't mesh well with the recently added REQUIRES_EXPR_EXTRA_ARGS
mechanism for delaying substitution into requires-expressions, which is
the cause of this PR.

But in order to avoid substituting through a lambda's constraints during
regeneration, we need to be able to get at all in-scope template
parameters and corresponding template arguments during constraint
checking of a lambda's op().  And this information is not easily
available when we need it, it seems.

To that end, the approach that this patch takes is to add two new fields
to LAMBDA_EXPR (and remove one): LAMBDA_EXPR_REGENERATED_FROM
(replacing LAMBDA_EXPR_INSTANTIATED), and LAMBDA_EXPR_REGENERATING_TARGS.
The former allows us to obtain the complete set of template parameters
that are in-scope for a lambda's op(), and the latter gives us all outer
template arguments that were used to regenerate the lambda (analogous to
the TI_TEMPLATE and TI_ARGS of a TEMPLATE_INFO, respectively).

LAMBDA_EXPR_REGENERATING_TARGS is not strictly necessary -- in an
earlier prototype, I walked LAMBDA_EXPR_EXTRA_SCOPE to build up this set
of outer template arguments on demand, but it seems cleaner to do it this
way.  (We'd need to walk LAMBDA_EXPR_EXTRA_SCOPE and not DECL/TYPE_CONTEXT
because the latter skips over variable template scopes.)

This patch also renames the predicate instantiated_lambda_fn_p to
regenerated_lambda_fn_p, for sake of consistency with the rest of the
patch which uses "regenerated" instead of "instantiated".

gcc/cp/ChangeLog:

	PR c++/99874
	* constraint.cc (get_normalized_constraints_from_decl): Handle
	regenerated lambdas.
	(satisfy_declaration_constraints): Likewise.  Check for
	dependent args later.
	* cp-tree.h (LAMBDA_EXPR_INSTANTIATED): Replace with ...
	(LAMBDA_EXPR_REGENERATED_FROM): ... this.
	(LAMBDA_EXPR_REGENERATING_TARGS): New.
	(tree_lambda_expr::regenerated_from): New data member.
	(tree_lambda_expr::regenerating_targs): New data member.
	(add_to_template_args): Declare.
	(regenerated_lambda_fn_p): Likewise.
	(most_general_lambda): Likewise.
	* lambda.c (build_lambda_expr): Set LAMBDA_EXPR_REGENERATED_FROM
	and LAMBDA_EXPR_REGENERATING_TARGS.
	* pt.c (add_to_template_args): No longer static.
	(tsubst_function_decl): Unconditionally propagate constraints on
	the substituted function decl.
	(instantiated_lambda_fn_p): Rename to ...
	(regenerated_lambda_fn_p): ... this.  Check
	LAMBDA_EXPR_REGENERATED_FROM instead of
	LAMBDA_EXPR_INSTANTIATED.
	(most_general_lambda): Define.
	(enclosing_instantiation_of): Adjust after renaming
	instantiated_lambda_fn_p.
	(tsubst_lambda_expr): Don't set LAMBDA_EXPR_INSTANTIATED.  Set
	LAMBDA_EXPR_REGENERATED_FROM and LAMBDA_EXPR_REGENERATING_TARGS.
	Don't substitute or set constraints on the regenerated lambda.

gcc/testsuite/ChangeLog:

	PR c++/99874
	* g++.dg/cpp2a/concepts-lambda16.C: New test.
	* g++.dg/cpp2a/concepts-lambda17.C: New test.
2021-04-08 13:07:43 -04:00
..
call.c c++: improve reference binding diagnostic [PR91849] 2021-04-08 12:02:27 -04:00
cfns.gperf
cfns.h
ChangeLog Daily bump. 2021-04-08 00:16:44 +00:00
ChangeLog-1993
ChangeLog-1994
ChangeLog-1995
ChangeLog-1996
ChangeLog-1997
ChangeLog-1998
ChangeLog-1999
ChangeLog-2000
ChangeLog-2001
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
ChangeLog-2018
ChangeLog-2019
ChangeLog-2020
ChangeLog.ptr
ChangeLog.tree-ssa
class.c c++: Add ABI version for PR98481 fix 2021-04-01 10:04:38 -04:00
config-lang.in
constexpr.c c++: Don't cache constexpr functions which are passed pointers to heap or static vars being constructed [PR99859] 2021-04-08 17:19:12 +02:00
constraint.cc c++: Don't substitute into constraints on lambdas [PR99874] 2021-04-08 13:07:43 -04:00
coroutines.cc coroutines: init struct members to NULL 2021-03-18 10:42:44 +01:00
cp-gimplify.c c++: Fix ICE on PTRMEM_CST in lambda in inline var initializer [PR99790] 2021-03-30 18:15:32 +02:00
cp-lang.c
cp-name-hint.h
cp-objcp-common.c
cp-objcp-common.h
cp-tree.def
cp-tree.h c++: Don't substitute into constraints on lambdas [PR99874] 2021-04-08 13:07:43 -04:00
cp-ubsan.c
cvt.c c++: PMF template parm and noexcept [PR90664] 2021-04-03 01:54:03 -04:00
cxx-pretty-print.c
cxx-pretty-print.h
decl2.c c++: Diagnose bare parameter packs in bitfield widths [PR99745] 2021-03-25 21:06:09 +01:00
decl.c c++: Fix ICE with unexpanded parameter pack [PR99844] 2021-04-08 07:44:44 -04:00
decl.h
dump.c
error.c c++: Fix pretty printing the context of local class [PR99213] 2021-02-25 16:44:34 -05:00
except.c c++: Fix ICE with unexpanded parameter pack [PR99844] 2021-04-08 07:44:44 -04:00
expr.c c++: Fix bogus -Wvolatile warning in C++20 [PR98947] 2021-02-05 11:11:04 -05:00
friend.c
g++spec.c
init.c c++: access checking in aggregate initialization [PR96673] 2021-04-06 16:08:40 -04:00
lambda.c c++: Don't substitute into constraints on lambdas [PR99874] 2021-04-08 13:07:43 -04:00
lang-specs.h
lex.c c++: Poor diagnostic in header-unit [PR 99468] 2021-03-08 10:40:09 -08:00
logic.cc
Make-lang.in c++: Fix alias comparison [PR98926] 2021-02-03 12:50:18 -05:00
mangle.c c++: mangling of lambdas in default args [PR91241] 2021-04-06 00:12:57 -04:00
mapper-client.cc modules : Make sure we include <map> in system.h. 2021-04-01 19:32:16 +01:00
mapper-client.h
mapper-resolver.cc modules : Make sure we include <map> in system.h. 2021-04-01 19:32:16 +01:00
method.c c++: GC collects live data when synthesizing operator== [PR99831] 2021-04-01 17:04:15 -04:00
module.cc c++: Unneeded export query [PR 99380] 2021-04-05 07:55:41 -07:00
name-lookup.c c++: using overloaded with local decl [PR92918] 2021-04-07 15:27:47 -04:00
name-lookup.h c++: support target attr for DECL_LOCAL_DECL_P fns [PR99108] 2021-03-16 10:54:23 -04:00
operators.def
optimize.c
parser.c c++: friend with redundant qualification [PR41723] 2021-04-07 17:01:52 -04:00
parser.h Objective-C++ : Fix handling of unnamed message parms [PR49070]. 2021-03-18 11:47:27 +00:00
pt.c c++: Don't substitute into constraints on lambdas [PR99874] 2021-04-08 13:07:43 -04:00
ptree.c c++: Fix print-tree for TEMPLATE_DECL 2021-04-05 08:25:26 -04:00
rtti.c PR c++/99251 - inconsistent -Wnonnull warning behaviour with dynamic_cast 2021-03-02 11:12:50 -07:00
search.c c++: private inheritance access diagnostics fix [PR17314] 2021-01-23 17:48:31 -05:00
semantics.c c++: Refine check for CTAD placeholder [PR99586] 2021-04-02 19:47:09 -04:00
tree.c c++: variadic lambda noexcept-specifier [PR99583] 2021-04-01 16:04:54 -04:00
type-utils.h c++: abbreviated function template return type rewriting [PR98990] 2021-02-25 19:55:43 -05:00
typeck2.c c++: array new initialized from a call [PR99643] 2021-04-03 20:59:00 -04:00
typeck.c c++: -Wunused, constant, and generic lambda [PR96311] 2021-04-05 17:27:24 -04:00
vtable-class-hierarchy.c