aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-05-05 17:39:19 -0400
committerJason Merrill <jason@redhat.com>2020-05-05 17:39:31 -0400
commit04b89192ace3a766a17374d5bef8fb19d9be2d7c (patch)
tree5311f78e69d7c223b1fbbee8f33d64a0f3a351f3 /gcc/cp/constexpr.c
parentd0aed8d5ba77e0756f3c9ebcd65eba1bfb11f24b (diff)
downloadgcc-04b89192ace3a766a17374d5bef8fb19d9be2d7c.zip
gcc-04b89192ace3a766a17374d5bef8fb19d9be2d7c.tar.gz
gcc-04b89192ace3a766a17374d5bef8fb19d9be2d7c.tar.bz2
c++: constexpr and lambda capture [PR90212]
This is the same issue as PR86429, just in potential_constant_expression_1 rather than cxx_eval_constant_expression. As in that case, when we're trying to evaluate a constant expression within a lambda, we don't have a constant closure object to refer to, but we can try to refer directly to the captured variable. gcc/cp/ChangeLog 2020-05-05 Jason Merrill <jason@redhat.com> PR c++/90212 * constexpr.c (potential_constant_expression_1): In a lambda function, consider a captured variable directly.
Diffstat (limited to 'gcc/cp/constexpr.c')
-rw-r--r--gcc/cp/constexpr.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 637cb74..706d8a1 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -7520,12 +7520,18 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
variable with automatic storage duration defined outside that
lambda-expression, where the reference would be an
odr-use. */
+
+ if (want_rval)
+ /* Since we're doing an lvalue-rvalue conversion, this might
+ not be an odr-use, so evaluate the variable directly. */
+ return RECUR (DECL_CAPTURED_VARIABLE (t), rval);
+
if (flags & tf_error)
{
tree cap = DECL_CAPTURED_VARIABLE (t);
error ("lambda capture of %qE is not a constant expression",
cap);
- if (!want_rval && decl_constant_var_p (cap))
+ if (decl_constant_var_p (cap))
inform (input_location, "because it is used as a glvalue");
}
return false;