c++: defer all consteval in default args [DR2631]
commit9bf74082bc93226e1ceb66430706e957e460c841
authorJason Merrill <jason@redhat.com>
Sat, 8 Oct 2022 00:34:53 +0000 (7 20:34 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 12 Oct 2022 15:38:05 +0000 (12 11:38 -0400)
tree43df246d62d87945fb10948b4cdab83734adfe55
parentbfcd9f84531fa99e9d00efd8bcfd3c8ac16fa360
c++: defer all consteval in default args [DR2631]

The proposed resolution of CWG2631 extends our current handling of
source_location::current to all consteval functions: default arguments
are not evaluated until they're used in a call, the same should apply to
evaluation of immediate invocations.  And similarly for default member
initializers.

Previously we folded source_location::current in cp_fold_r; now we fold all
consteval calls in default arguments/member initializers in bot_replace.

DR 2631

gcc/cp/ChangeLog:

* cp-tree.h (source_location_current_p): Remove.
* name-lookup.h (struct cp_binding_level): Remove
immediate_fn_ctx_p.
* call.cc (in_immediate_context): All default args
and DMI are potentially immediate context.
(immediate_invocation_p): Don't treat source_location specially.
(struct in_consteval_if_p_temp_override): Move to cp-tree.h.
* constexpr.cc (get_nth_callarg): Move to cp-tree.h.
* cp-gimplify.cc (cp_fold_r): Don't fold consteval.
* name-lookup.cc (begin_scope): Don't set immediate_fn_ctx_p.
* parser.cc (cp_parser_lambda_declarator_opt): Likewise.
(cp_parser_direct_declarator): Likewise.
* pt.cc (tsubst_default_argument): Open sk_function_parms level.
* tree.cc (source_location_current_p): Remove.
(bot_replace): Fold consteval here.
(break_out_target_exprs): Handle errors.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval-defarg3.C: New test.
gcc/cp/call.cc
gcc/cp/constexpr.cc
gcc/cp/cp-gimplify.cc
gcc/cp/cp-tree.h
gcc/cp/name-lookup.cc
gcc/cp/name-lookup.h
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/cp/tree.cc
gcc/testsuite/g++.dg/cpp2a/consteval-defarg3.C [new file with mode: 0644]