From: Marek Polacek Date: Tue, 5 Feb 2019 21:30:51 +0000 (+0000) Subject: PR c++/89158 - by-value capture of constexpr variable broken. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0d806438807541d31a759f687279e704ad103609;p=gcc.git PR c++/89158 - by-value capture of constexpr variable broken. * call.c (convert_like_real) : Call mark_exp_read instead of mark_rvalue_use. * g++.dg/cpp0x/lambda/lambda-89158.C: New test. From-SVN: r268561 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 65a850fc53c..8ebbc1266ed 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-02-05 Marek Polacek + + PR c++/89158 - by-value capture of constexpr variable broken. + * call.c (convert_like_real) : Call mark_exp_read + instead of mark_rvalue_use. + 2019-02-05 Alexandre Oliva PR c++/87770 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index c74d1b4ebdf..18b813866c8 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7006,7 +7006,9 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, return expr; } - expr = mark_rvalue_use (expr); + /* We don't know here whether EXPR is being used as an lvalue or + rvalue, but we know it's read. */ + mark_exp_read (expr); /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow any more UDCs. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 68ce1a46f32..71ea3661995 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-05 Marek Polacek + + PR c++/89158 - by-value capture of constexpr variable broken. + * g++.dg/cpp0x/lambda/lambda-89158.C: New test. + 2019-02-05 Segher Boessenkool * gcc.dg/vect/pr84711.c: Use -Wno-psabi. diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-89158.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-89158.C new file mode 100644 index 00000000000..15f15b46875 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-89158.C @@ -0,0 +1,11 @@ +// PR c++/89158 +// { dg-do compile { target c++11 } } + +struct T { T(const int&); }; +void Func(T); + +void test() +{ + constexpr int Val = 42; + [Val]() { Func(Val); }; +}