Skip to content

Commit 4073a79

Browse files
committed
c++: capture folding and lvalueness checking [PR125408]
Here after the recursive mark_rvalue_use we end up with a VAR_DECL in r, so the assert fails. But in that case r is still an lvalue, so we don't need to do any adjustment. Fixed by adjusting the condition to detect the case we actually need to fix up, i.e. when ref is an lvalue and r is not. The previous !rvalue_p condition doesn't make much sense; rvalue_p indicates whether we want to do an lvalue-rvalue conversion on expr, not whether expr was already an rvalue. PR c++/125408 gcc/cp/ChangeLog: * expr.cc (mark_use): Fix condition for changing rvalue to lvalue. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-targ34.C: New test.
1 parent 41006b6 commit 4073a79

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

gcc/cp/expr.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
186186
return error_mark_node;
187187
if (r != ref)
188188
{
189-
if (!rvalue_p)
189+
if (DECL_P (ref) && !lvalue_p (r))
190190
{
191191
/* Make sure we still return an lvalue. */
192192
gcc_assert (TREE_CODE (r) == NOP_EXPR);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// PR c++/125408
2+
// { dg-do compile { target c++20 } }
3+
4+
struct Role {
5+
long id;
6+
};
7+
8+
template <typename T>
9+
struct StaticObj {
10+
inline static T obj;
11+
};
12+
13+
template<int... I> struct A { };
14+
15+
template <auto Ptr, typename Table>
16+
constexpr int find_member_index() {
17+
constexpr auto& t = StaticObj<Table>::obj;
18+
19+
[&]<int... Idx>(A<Idx...>) {
20+
([&]{
21+
using T1 = decltype(&(t.*Ptr));
22+
auto p = &(t.*Ptr);
23+
return Idx;
24+
}(), ...);
25+
}(A<0,1>{});
26+
return 42;
27+
}
28+
29+
auto p = find_member_index<&Role::id, Role>();
30+
31+
int main() {}

0 commit comments

Comments
 (0)