https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/91933
>From 4cadff527e02ae03aa5850ee713fe57aee663a52 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Mon, 13 May 2024 10:00:19 +0200 Subject: [PATCH 1/5] [Clang] Fix dependency computation for pack indexing expression Given `foo...[idx]` if idx is value dependent, the expression is type dependent. Fixes #91885 Fixes #91884 --- clang/lib/AST/ComputeDependence.cpp | 3 +++ clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp index bad8e75b2f878..ee56c50d76512 100644 --- a/clang/lib/AST/ComputeDependence.cpp +++ b/clang/lib/AST/ComputeDependence.cpp @@ -376,6 +376,9 @@ ExprDependence clang::computeDependence(PackExpansionExpr *E) { ExprDependence clang::computeDependence(PackIndexingExpr *E) { ExprDependence D = E->getIndexExpr()->getDependence(); + if (D & ExprDependence::Value) + D |= ExprDependence::TypeInstantiation; + ArrayRef<Expr *> Exprs = E->getExpressions(); if (Exprs.empty()) D |= (E->getPackIdExpression()->getDependence() | diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp index a3e5a0931491b..764f6163710bd 100644 --- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp +++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp @@ -194,3 +194,17 @@ void h() { // expected-note-re@-2 {{function template specialization '{{.*}}' requested here}} } } + +namespace GH91885 { + +void test(auto...args){ + [&]<int idx>(){ + using R = decltype( args...[idx] ) ; + }.template operator()<0>(); +} + +void f( ) { + test(1); +} + +} >From 7c9192cffe099fe4a35e8cb9a88ec56b4480daa1 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Mon, 13 May 2024 14:24:34 +0200 Subject: [PATCH 2/5] address review feedback --- clang/lib/AST/ComputeDependence.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp index ee56c50d76512..bd0519a1787cc 100644 --- a/clang/lib/AST/ComputeDependence.cpp +++ b/clang/lib/AST/ComputeDependence.cpp @@ -377,7 +377,7 @@ ExprDependence clang::computeDependence(PackExpansionExpr *E) { ExprDependence clang::computeDependence(PackIndexingExpr *E) { ExprDependence D = E->getIndexExpr()->getDependence(); if (D & ExprDependence::Value) - D |= ExprDependence::TypeInstantiation; + D |= E->getPackIdExpression()->getDependence() & ExprDependence::Type; ArrayRef<Expr *> Exprs = E->getExpressions(); if (Exprs.empty()) >From 320b9fe584d02e5f156ff012b3c0facf9cc06e7b Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Mon, 13 May 2024 15:56:02 +0200 Subject: [PATCH 3/5] add additional test --- clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp index 764f6163710bd..ef35a49023952 100644 --- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp +++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp @@ -203,8 +203,17 @@ void test(auto...args){ }.template operator()<0>(); } +template<int...args> +void test2(){ + [&]<int idx>(){ + using R = decltype( args...[idx] ) ; + }.template operator()<0>(); +} + void f( ) { - test(1); + test(1); + test2<1>(); } + } >From bb6b680b8200e2cc7c6e8059be31959b2dfb4a51 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Mon, 13 May 2024 17:34:36 +0200 Subject: [PATCH 4/5] Fix tests? --- clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp index ef35a49023952..0ac85b5bcc14b 100644 --- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp +++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp @@ -203,7 +203,7 @@ void test(auto...args){ }.template operator()<0>(); } -template<int...args> +template<int... args> void test2(){ [&]<int idx>(){ using R = decltype( args...[idx] ) ; >From fdd321f94f29e37648a956d2fff9a9e9e739f10c Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Mon, 13 May 2024 19:20:32 +0200 Subject: [PATCH 5/5] Fix getDecltypeForExpr + cleanup --- clang/lib/AST/ComputeDependence.cpp | 14 +++++++++----- clang/lib/Sema/SemaType.cpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp index bd0519a1787cc..62ca15ea398f5 100644 --- a/clang/lib/AST/ComputeDependence.cpp +++ b/clang/lib/AST/ComputeDependence.cpp @@ -375,15 +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::Value) - D |= E->getPackIdExpression()->getDependence() & ExprDependence::Type; + 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 fddc3545ecb61..a3b74958fdcf6 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -9806,7 +9806,7 @@ 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()) + if (E->isInstantiationDependent()) return Context.DependentTy; Expr *IDExpr = E; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits