diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2c6c7e083b9c9..7a9e7f0b4eba6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -309,6 +309,8 @@ Bug Fixes to C++ Support template depth than the friend function template. (#GH98258) - Clang now rebuilds the template parameters of out-of-line declarations and specializations in the context of the current instantiation in all cases. +- Fix evaluation of the index of dependent pack indexing expressions/types specifiers (#GH105900) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 62287c2d26375..b3854cd8f8222 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6669,9 +6669,15 @@ QualType TreeTransform::TransformPackIndexingType(TypeLocBuilder &TLB, PackIndexingTypeLoc TL) { // Transform the index - ExprResult IndexExpr = getDerived().TransformExpr(TL.getIndexExpr()); - if (IndexExpr.isInvalid()) - return QualType(); + ExprResult IndexExpr; + { + EnterExpressionEvaluationContext ConstantContext( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); + + IndexExpr = getDerived().TransformExpr(TL.getIndexExpr()); + if (IndexExpr.isInvalid()) + return QualType(); + } QualType Pattern = TL.getPattern(); const PackIndexingType *PIT = TL.getTypePtr(); @@ -15299,9 +15305,14 @@ TreeTransform::TransformPackIndexingExpr(PackIndexingExpr *E) { return E; // Transform the index - ExprResult IndexExpr = getDerived().TransformExpr(E->getIndexExpr()); - if (IndexExpr.isInvalid()) - return ExprError(); + ExprResult IndexExpr; + { + EnterExpressionEvaluationContext ConstantContext( + SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); + IndexExpr = getDerived().TransformExpr(E->getIndexExpr()); + if (IndexExpr.isInvalid()) + return ExprError(); + } SmallVector ExpandedExprs; if (!E->expandsToEmptyPack() && E->getExpressions().empty()) { diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp index 9ea90a4c3e30f..7d7e808746217 100644 --- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp +++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp @@ -231,3 +231,31 @@ struct type_info { namespace GH93650 { auto func(auto... inputArgs) { return typeid(inputArgs...[0]); } } // namespace GH93650 + + +namespace GH105900 { + +template +struct types { + template + static constexpr __SIZE_TYPE__ get_index() { return idx; } + + template + static auto x() -> opts...[get_index()] {} +}; + +template +struct vars { + template + static constexpr __SIZE_TYPE__ get_index() { return idx; } + + template + static auto x() -> decltype(opts...[get_index()]) {return 0;} +}; + +void f() { + types::x<0>(); + vars<0>::x<0>(); +} + +}