[clang] 312f83f - [Clang] Fix dependency computation for pack indexing expression (#91933)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 06:37:10 PDT 2024
Author: cor3ntin
Date: 2024-05-14T15:37:06+02:00
New Revision: 312f83f0e0672118a6d82d4b4d3568e9c812086d
URL: https://github.com/llvm/llvm-project/commit/312f83f0e0672118a6d82d4b4d3568e9c812086d
DIFF: https://github.com/llvm/llvm-project/commit/312f83f0e0672118a6d82d4b4d3568e9c812086d.diff
LOG: [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
Added:
Modified:
clang/lib/AST/ComputeDependence.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/cxx2c-pack-indexing.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index bad8e75b2f878..62ca15ea398f5 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -375,12 +375,19 @@ ExprDependence clang::computeDependence(PackExpansionExpr *E) {
}
ExprDependence clang::computeDependence(PackIndexingExpr *E) {
+
+ ExprDependence PatternDep = E->getPackIdExpression()->getDependence() &
+ ~ExprDependence::UnexpandedPack;
+
ExprDependence D = E->getIndexExpr()->getDependence();
+ if (D & ExprDependence::TypeValueInstantiation)
+ D |= E->getIndexExpr()->getDependence() | PatternDep |
+ ExprDependence::Instantiation;
+
ArrayRef<Expr *> Exprs = E->getExpressions();
if (Exprs.empty())
- D |= (E->getPackIdExpression()->getDependence() |
- ExprDependence::TypeValueInstantiation) &
- ~ExprDependence::UnexpandedPack;
+ D |= PatternDep | ExprDependence::Instantiation;
+
else if (!E->getIndexExpr()->isInstantiationDependent()) {
std::optional<unsigned> Index = E->getSelectedIndex();
assert(Index && *Index < Exprs.size() && "pack index out of bound");
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index bfa3799bda06e..d65fafc8cf4f7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9351,15 +9351,20 @@ QualType Sema::BuildCountAttributedArrayType(QualType WrappedTy,
/// that expression, according to the rules in C++11
/// [dcl.type.simple]p4 and C++11 [expr.lambda.prim]p18.
QualType Sema::getDecltypeForExpr(Expr *E) {
- if (E->isTypeDependent())
- return Context.DependentTy;
Expr *IDExpr = E;
if (auto *ImplCastExpr = dyn_cast<ImplicitCastExpr>(E))
IDExpr = ImplCastExpr->getSubExpr();
- if (auto *PackExpr = dyn_cast<PackIndexingExpr>(E))
- IDExpr = PackExpr->getSelectedExpr();
+ if (auto *PackExpr = dyn_cast<PackIndexingExpr>(E)) {
+ if (E->isInstantiationDependent())
+ IDExpr = PackExpr->getPackIdExpression();
+ else
+ IDExpr = PackExpr->getSelectedExpr();
+ }
+
+ if (E->isTypeDependent())
+ return Context.DependentTy;
// C++11 [dcl.type.simple]p4:
// The type denoted by decltype(e) is defined as follows:
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index a3e5a0931491b..0ac85b5bcc14b 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -194,3 +194,26 @@ void h() {
// expected-note-re at -2 {{function template specialization '{{.*}}' requested here}}
}
}
+
+namespace GH91885 {
+
+void test(auto...args){
+ [&]<int idx>(){
+ using R = decltype( args...[idx] ) ;
+ }.template operator()<0>();
+}
+
+template<int... args>
+void test2(){
+ [&]<int idx>(){
+ using R = decltype( args...[idx] ) ;
+ }.template operator()<0>();
+}
+
+void f( ) {
+ test(1);
+ test2<1>();
+}
+
+
+}
More information about the cfe-commits
mailing list