Skip to content

Commit 351e4fa

Browse files
authored
[Clang] Fix assert when transforming a pack indexing type. (llvm#82234)
When a pack in a pack indexing specifier cannot be immediately expanded, we were creating an incomplete TypeLoc (causing assertion failure). As we do not keep track of typelocs of expanded elements, we create a trivial typeloc Fixes llvm#81697
1 parent a445474 commit 351e4fa

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6561,7 +6561,11 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
65616561
return QualType();
65626562
if (!ShouldExpand) {
65636563
Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6564-
QualType Pack = getDerived().TransformType(T);
6564+
// FIXME: should we keep TypeLoc for individual expansions in
6565+
// PackIndexingTypeLoc?
6566+
TypeSourceInfo *TI =
6567+
SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6568+
QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
65656569
if (Pack.isNull())
65666570
return QualType();
65676571
if (NotYetExpanded) {

clang/test/SemaCXX/cxx2c-pack-indexing.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,22 @@ using Splice = typename SpliceImpl<Tl, Il>::type;
135135
using type = Splice<TL<char, short, long, double>, IL<1, 2>>;
136136
static_assert(is_same<type, TL<short, long>>);
137137
}
138+
139+
140+
namespace GH81697 {
141+
142+
template<class... Ts> struct tuple {
143+
int __x0;
144+
};
145+
146+
template<auto I, class... Ts>
147+
Ts...[I]& get(tuple<Ts...>& t) {
148+
return t.__x0;
149+
}
150+
151+
void f() {
152+
tuple<int> x;
153+
get<0>(x);
154+
}
155+
156+
}

0 commit comments

Comments
 (0)