]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: parameterized requires-expr as default argument [PR101725]
authorPatrick Palka <ppalka@redhat.com>
Wed, 11 Aug 2021 20:53:53 +0000 (16:53 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 11 Aug 2021 21:40:42 +0000 (17:40 -0400)
commitbe45bc283e1821fff463d03d5115cd4db634ed84
tree399e8ea42e9e9a4c029565f6c03597f87a2888fb
parent4ee9e57684e27d27ff12e2b93ab7ae3d46861593
c++: parameterized requires-expr as default argument [PR101725]

Here we're rejecting the default template argument

  requires (T t) { x(t); }

because we consider the 't' in the requirement to be a local variable
(according to local_variable_p), and we generally forbid local variables
from appearing inside default arguments.  We can perhaps fix this by
giving special treatment to parameters introduced by requires-expressions,
but DR 2082 relaxed the restriction about local variables appearing within
default arguments to permit them inside unevaluated operands thereof.
So this patch just implements DR 2082 which also fixes this PR since a
requires-expression is an unevaluated context.

PR c++/101725
DR 2082

gcc/cp/ChangeLog:

* cp-tree.h (unevaluated_p): Return true for REQUIRES_EXPR.
* decl.c (local_variable_p_walkfn): Don't walk into unevaluated
operands.
* parser.c (cp_parser_primary_expression) <case CPP_NAME>: Never
reject uses of local variables in unevaluated contexts.
* tree.c (cp_walk_subtrees) <case REQUIRES_EXPR>: Increment
cp_unevaluated_operand.  Use cp_walk_tree directly instead of
WALK_SUBTREE to avoid the goto.  Use REQUIRES_EXPR_REQS instead
of TREE_OPERAND directly.

gcc/testsuite/ChangeLog:

* g++.dg/DRs/dr2082.C: New test.
* g++.dg/cpp2a/concepts-uneval4.C: New test.

(cherry picked from commit 9707d2e5dbb92d2bc990c922461a5a16ae652319)
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/parser.c
gcc/cp/tree.c
gcc/testsuite/g++.dg/DRs/dr2082.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-uneval4.C [new file with mode: 0644]