Skip to content

Commit 41006b6

Browse files
committed
c++: typedef in lambda in pack expansion
In trying to reduce the testcase for PR125408, I came across an older regression, dating back to r14-9938, though the problem wasn't in that commit. cp_walk_subtrees avoids walking into uses of typedefs because it wants to look at what's actually written. But here we were also skipping over the definition of the typedef, so extract_locals_r never got to see the use of 't', so later substitution failed. Fixed by specifically handling typedef DECL_EXPR. PR c++/125408 gcc/cp/ChangeLog: * tree.cc (cp_walk_subtrees): Walk into the DECL_ORIGINAL_TYPE of a typedef DECL_EXPR. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-targ33.C: New test.
1 parent e259a18 commit 41006b6

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

gcc/cp/tree.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6407,6 +6407,10 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func,
64076407
WALK_SUBTREE (DECL_SIZE (decl));
64086408
WALK_SUBTREE (DECL_SIZE_UNIT (decl));
64096409
}
6410+
if (is_typedef_decl (TREE_OPERAND (t, 0)))
6411+
/* We avoid walking into typedefs above, but we do want to walk
6412+
into them if we're looking at the actual declaration. */
6413+
WALK_SUBTREE (DECL_ORIGINAL_TYPE (TREE_OPERAND (t, 0)));
64106414
break;
64116415

64126416
case LAMBDA_EXPR:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// PR c++/125408
2+
// { dg-do compile { target c++20 } }
3+
4+
struct Role {
5+
long id;
6+
};
7+
8+
template <typename T> T Obj;
9+
template<int... I> struct A { };
10+
void sink(...);
11+
12+
template <auto Ptr, typename Table>
13+
constexpr int find_member_index() {
14+
constexpr auto& t = Obj<Table>;
15+
[]<int... Idx>(A<Idx...>) {
16+
sink([]() {
17+
using T1 = decltype(&(t.*Ptr));
18+
return Idx;
19+
}() ...);
20+
}(A<1,2>{});
21+
return 42;
22+
}
23+
24+
auto i = find_member_index<&Role::id, Role>();

0 commit comments

Comments
 (0)