diff options
author | Patrick Palka <ppalka@redhat.com> | 2021-08-11 16:53:53 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2021-08-11 16:53:53 -0400 |
commit | 9707d2e5dbb92d2bc990c922461a5a16ae652319 (patch) | |
tree | 0c36cbadf41c64bdcb4cc6f4bb66e1d0eb42c68d /gcc/cp/decl.c | |
parent | ee8f9ff00d79998274c967ad0c23692be9dd3ada (diff) | |
download | gcc-9707d2e5dbb92d2bc990c922461a5a16ae652319.zip gcc-9707d2e5dbb92d2bc990c922461a5a16ae652319.tar.gz gcc-9707d2e5dbb92d2bc990c922461a5a16ae652319.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f626f1e..b3671ee 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14270,6 +14270,14 @@ static tree local_variable_p_walkfn (tree *tp, int *walk_subtrees, void * /*data*/) { + if (unevaluated_p (TREE_CODE (*tp))) + { + /* DR 2082 permits local variables in unevaluated contexts + within a default argument. */ + *walk_subtrees = 0; + return NULL_TREE; + } + if (local_variable_p (*tp) && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier)) return *tp; |