Skip to content

Commit 312f83f

Browse files
authored
[Clang] Fix dependency computation for pack indexing expression (#91933)
Given `foo...[idx]` if idx is value dependent, the expression is type dependent. Fixes #91885 Fixes #91884
1 parent 725014d commit 312f83f

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

clang/lib/AST/ComputeDependence.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,19 @@ ExprDependence clang::computeDependence(PackExpansionExpr *E) {
375375
}
376376

377377
ExprDependence clang::computeDependence(PackIndexingExpr *E) {
378+
379+
ExprDependence PatternDep = E->getPackIdExpression()->getDependence() &
380+
~ExprDependence::UnexpandedPack;
381+
378382
ExprDependence D = E->getIndexExpr()->getDependence();
383+
if (D & ExprDependence::TypeValueInstantiation)
384+
D |= E->getIndexExpr()->getDependence() | PatternDep |
385+
ExprDependence::Instantiation;
386+
379387
ArrayRef<Expr *> Exprs = E->getExpressions();
380388
if (Exprs.empty())
381-
D |= (E->getPackIdExpression()->getDependence() |
382-
ExprDependence::TypeValueInstantiation) &
383-
~ExprDependence::UnexpandedPack;
389+
D |= PatternDep | ExprDependence::Instantiation;
390+
384391
else if (!E->getIndexExpr()->isInstantiationDependent()) {
385392
std::optional<unsigned> Index = E->getSelectedIndex();
386393
assert(Index && *Index < Exprs.size() && "pack index out of bound");

clang/lib/Sema/SemaType.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9351,15 +9351,20 @@ QualType Sema::BuildCountAttributedArrayType(QualType WrappedTy,
93519351
/// that expression, according to the rules in C++11
93529352
/// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18.
93539353
QualType Sema::getDecltypeForExpr(Expr *E) {
9354-
if (E->isTypeDependent())
9355-
return Context.DependentTy;
93569354

93579355
Expr *IDExpr = E;
93589356
if (auto *ImplCastExpr = dyn_cast<ImplicitCastExpr>(E))
93599357
IDExpr = ImplCastExpr->getSubExpr();
93609358

9361-
if (auto *PackExpr = dyn_cast<PackIndexingExpr>(E))
9362-
IDExpr = PackExpr->getSelectedExpr();
9359+
if (auto *PackExpr = dyn_cast<PackIndexingExpr>(E)) {
9360+
if (E->isInstantiationDependent())
9361+
IDExpr = PackExpr->getPackIdExpression();
9362+
else
9363+
IDExpr = PackExpr->getSelectedExpr();
9364+
}
9365+
9366+
if (E->isTypeDependent())
9367+
return Context.DependentTy;
93639368

93649369
// C++11 [dcl.type.simple]p4:
93659370
// The type denoted by decltype(e) is defined as follows:

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,26 @@ void h() {
194194
// expected-note-re@-2 {{function template specialization '{{.*}}' requested here}}
195195
}
196196
}
197+
198+
namespace GH91885 {
199+
200+
void test(auto...args){
201+
[&]<int idx>(){
202+
using R = decltype( args...[idx] ) ;
203+
}.template operator()<0>();
204+
}
205+
206+
template<int... args>
207+
void test2(){
208+
[&]<int idx>(){
209+
using R = decltype( args...[idx] ) ;
210+
}.template operator()<0>();
211+
}
212+
213+
void f( ) {
214+
test(1);
215+
test2<1>();
216+
}
217+
218+
219+
}

0 commit comments

Comments
 (0)