[clang] [Clang] Fix dependency computation for pack indexing expression (PR #91933)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 08:35:07 PDT 2024
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 <corentinjabot at gmail.com>
Date: Mon, 13 May 2024 10:00:19 +0200
Subject: [PATCH 1/4] [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 at -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 <corentinjabot at gmail.com>
Date: Mon, 13 May 2024 14:24:34 +0200
Subject: [PATCH 2/4] 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 <corentinjabot at gmail.com>
Date: Mon, 13 May 2024 15:56:02 +0200
Subject: [PATCH 3/4] 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 <corentinjabot at gmail.com>
Date: Mon, 13 May 2024 17:34:36 +0200
Subject: [PATCH 4/4] 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] ) ;
More information about the cfe-commits
mailing list