On Tue, Feb 05, 2019 at 01:24:15PM -0500, Jason Merrill wrote: > On 2/5/19 11:31 AM, Jakub Jelinek wrote: > > On Tue, Feb 05, 2019 at 11:24:14AM -0500, Jason Merrill wrote: > > > Yes, thanks, mark_rvalue_use is definitely wrong here. But > > > mark_lvalue_use > > > might be wrong as well; we don't know here how the expression is used by > > > the > > > inner conversions for the user-defined conversion. Can we remove the call > > > entirely? It doesn't seem to break any Wunused* tests. > > > > It was added in r159096 for -Wunused-but-set*. It is surely possible it is > > now covered by other mark_*_use calls. Or could we call there just > > mark_exp_read instead? > > That would be fine too.
So how about this if it passes testing? Bootstrapped/regtested running on x86_64-linux, ok for trunk/8? 2019-02-05 Marek Polacek <pola...@redhat.com> PR c++/89158 - by-value capture of constexpr variable broken. * call.c (convert_like_real) <case ck_user>: Call mark_exp_read instead of mark_rvalue_use. * g++.dg/cpp0x/lambda/lambda-89158.C: New test. diff --git gcc/cp/call.c gcc/cp/call.c index c74d1b4ebdf..020a095dade 100644 --- gcc/cp/call.c +++ 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); + /* Calling mark_rvalue_use could turn a decl into a constant, breaking + e.g. the need_temporary_p assumption in the ICS. */ + mark_exp_read (expr); /* Pass LOOKUP_NO_CONVERSION so rvalue/base handling knows not to allow any more UDCs. */ diff --git gcc/testsuite/g++.dg/cpp0x/lambda/lambda-89158.C gcc/testsuite/g++.dg/cpp0x/lambda/lambda-89158.C new file mode 100644 index 00000000000..15f15b46875 --- /dev/null +++ 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); }; +}